Adding a object(User) to a OU from a powershell

Qasim Afzal 101 Reputation points

I have checked the command and the format for the script not sure what's wrong.

I have added the screenshot for proof and the error message.

I switched the OU path to see if it would make any difference.. but yet it didn't.

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
27,013 questions
0 comments No comments
{count} votes

Accepted answer
  1. Sandeep G-MSFT 7,281 Reputation points Microsoft Employee

    @Qasim Afzal

    I tried the same command and it worked for me as expected in my lab. I used below command,


    You can also try to create the user first using powershell and then move the user to specific OU using below command,

    Move-ADObject -Identity "CN=expiry,CN=Users,DC=magic,DC=local" -TargetPath "OU=test,OU=Sync,DC=magic,DC=local"

    Even this command worked for me in my lab.


    Do let me know if you have any further questions.

    Please "Accept the answer" if the information helped you. This will help us and others in the community as well.

1 additional answer

Sort by: Most helpful
  1. Rich Matheisen 38,831 Reputation points

    Don't try to do everything on one line. Place the Read-Host before the Add-NewADUser and store the secure string in a variable. Use that variable as the value for the -AccountPassword parameter.