powershell - Creating ad user account with distinguished name -


for life of me, can't figure way either create new ad account distinguished name firstname lastname instead of username or modifying afterwards.

new-aduser -samaccountname $username -name $username -displayname $displayname -givenname $firstname -surname $lastname -userprincipalname $mailaddress -accountpassword (convertto-securestring $password -asplaintext -force) ` -enabled $false -path $ou -changepasswordatlogon $true -server ad.corp.com -mobilephone $mobilenumber -officephone $officenumber -title $jobtitle $fullname = $firstname + " " + $lastname $distinguishedname="cn=" + $fullname + ", " + $ou set-aduser $distinguishedname 

the set-aduser returns "directory not found" makes sense since distinguished name username.

thanks

you can assign newly created aduser variable , set name follows:

$params = @{     samaccountname        = $username     name                  = $username     displayname           = $displayname     givenname             = $firstname     surname               = $lastname     userprincipalname     = $mailaddress     accountpassword       = (convertto-securestring $password -asplaintext -force)     enabled               = $false     path                  = $ou     changepasswordatlogon = $true     server                = 'ad.corp.com'     mobilephone           = $mobilenumber     officephone           = $officenumber     title                 = $jobtitle     passthru              = $true } $aduser = new-aduser @params 

i couldn't test this, should work:

$distinguishedname = "cn=$firstname $lastname, $ou" $aduser.distinguishedname = $distinguishedname 

Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -