Executing local variable to a remote Active Directory server


hi,

remote pc tried using below command create users in ad. in "-path" section getting error. please me resolve this.

-----------------------------------------------
$theou = "hr"
#status = success :|

$myou = invoke-command -computername dc01 -scriptblock {"(get-adorganizationalunit -ldapfilter '(name=$theou)' -searchbase 'ou=users,ou=labou,dc=cyquent,dc=ae').distinguishedname" }
#status = success :|


invoke-command -computername dc01 -scriptblock {new-aduser -displayname peter -path $myou -givenname peter -city houston -country -description accountant -surname jason -name peter -samaccountname peter -userprincipalname peter -accountpassword (convertto-securestring password@123 -asplaintext -force) -changepasswordatlogon:$true -enabled:$true}

#status = error :oops:
error: cannot validate argument on parameter 'path'. argument null or empty. provide argument not null or
empty, , try command again.
----------------------------------------------------------


note:- if type -path -path 'ou=hr,ou=users,ou=labou,dc=cyquent,dc=ae' able create user successfully.

need use through variable trying.

note: - "hr" organization unit name trying create user. :|

plz me.

thanks,
shamir

i try point inm right direction.  @ how structured.

# in script session $global:session=new-pssession dc01  # later  $userprops=@{     displayname='peter'      path=$myou     givenname='peter'     city='houston'     country='us'     description='accountant'     surname='jason'     name='peter'     samaccountname='peter'     userprincipalname='peter'     accountpassword=(convertto-securestring 'password@123' -asplaintext -force)     changepasswordatlogon=$true      enabled=$true }  # send values hash remote system
$sb={
    $p=$args[0]
    new-aduser @p
}
invoke-command -session $session -scriptblock $sb -argumentlist $userprops


¯\_(ツ)_/¯






Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

Generating Event ID 91, 44 with CA (In Event Viewer with source as Certsvc)

Group policy default policy cannot be edited because network name not found

Problem when changing update source