Here is the Command I am 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 "[email protected]"
The Error Message I get:
ObjectNotFound: (CN=FIRST LAST...DC=OPR,DC=Local:String)
Once I remove the $Dpart
from the -Path
the command fires off correctly, but does not place the person into the correct OU. The command is filtered before hand and matches the name inside AD of the sub OU.
How can I use a variable inside the path command? I know it's simple, but I am just starting off with powershell.
It was so obvious that a snake would have bit me...
Lowest level OU first, then each level up after that. So,
OU=$Dpart, OU=Employees