AD Powershell help

Soldato
Joined
14 Mar 2004
Posts
8,040
Location
Brit in the USA
So I made a new OU in Active Directory and now I need to add users to it in Powershell. I'm a Powershell noob and am very confused. I assume I need to use the New-ADuser cmdlet? How do I specify which OU I want to add the user to?
Thanks!
 
Go to the Microsoft script centre and pull on of their scripts.
What version of OS are you running? 2008 r2, 2012? Some scripts will be written for v3/4 of powershell which won't work on 2008r2 (although you can upgrade)

No need to re-invent the wheel on this one:

http://gallery.technet.microsoft.com/scriptcenter

If all you want to do is get the job done then this is probably the best way.

If you're interested in learning how to write the script then check out the Technet article:

Windows Server 2008 R2
Windows Server 2012 R2

But Uhtred is correct in that the "-path" parameter is the one to define the OU in the way that Uhtred showed.
 
Last edited:
Do you have a lot of users? You could give solarwinds user import tools a go. Saves messing around with powershell (ideal for me as I've not used it very much).
 
Thanks, guys.

Got a bit further, but now I'm getting an error. Here is the command I'm using (I know I would normally use a script or tool for this, but I'd like to get it working purely from the command line right now)

new-ADUser -Name "Bob Smith" -SamAccountName "bsmith" - GivenName "Bob" -SurName "Smith" -path 'OU=NameOfOU, DC=NameOfDomain, dc=local' -Enabled $true -AccountPassword (Read-Host -AsSecureString "Type password here:") -ChangePasswordAtLogon $true

It asks for the password, then I get "The server is unwilling to process the request"

Any ideas?

Thanks again!

EDIT: LOL - always the way..post this and then find the answer 1 minute later :D should have been dc=com instead of dc=local.
 
Last edited:
you've solved this problem but the powershell cmdlets also have pretty good help built-in:
get-help new-aduser
get-help new-aduser -online
 
Back
Top Bottom