Adjusting variables in the new-aduser -path option in powershell
Here is the command I'm trying to work with:
New-ADUser -name "$firstName $lastName" -SamAccountName "$firstName.$lastName" -GivenName "$firstName" -Surname "$lastName" -DisplayName "$firstName $lastName" -Path "OU=Employees,OU=$Dpart,DC=OPR,DC=Local" -Enabled $true -AccountPassword $PWD -ChangePasswordAtLogon $true -EmailAddress "$firstName.$lastName@opr.org"
The error message I receive is:
ObjectNotFound: (CN=FIRST LAST...DC=OPR,DC=Local:String)
Once I remove $Dpart
from -Path
, the command fires correctly, but does not place the person in the correct unit. The command is filtered before hand and matches the name within the AD of the additional unit.
How can I use a variable inside the path command? I know it's simple, but I'm just getting started with powershell.
+3
source to share
1 answer
New-ADUser -name "$firstName $lastName" -SamAccountName "$firstName.$lastName" -GivenName "$firstName" -Surname "$lastName" -DisplayName "$firstName $lastName" -Path "OU=$Dpart,OU=Employees,DC=OPR,DC=Local" -Enabled $true -AccountPassword $PWD -ChangePasswordAtLogon $true -EmailAddress "$firstName.$lastName@opr.org"
It was so obvious that the snake could beat me ...
Low level lesson first, then each level up after that. So,OU=$Dpart, OU=Employees
+1
source to share