Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Having some trouble creating a command to create a new user in powerShell, the code I'm using is:

PS C:\Users\Nicky> New-ADUser -Name johnd -GivenName John -Surname Doe -DisplayName John Doe $secpasswd = ConvertTo-SecureString -String "pa$$word1" -AsPlainText -Force -AccountPassword $secpasswd

I can get it working without the AccountPassword, so I think the issue is when converting it to a secure string so the -AccountPassword will accept it

Anyone any ideas on how to get this to work?

Thanks

share|improve this question

Your syntax is wrong. Take a look at New-ADuser help page from Microsoft and this one from SS64. Also if you have spaces in your string (example: John Doe) you should single quote it.

It should have a syntax similar to this:

New-ADUser [-Name] <string> [-AccountExpirationDate <System.Nullable[System.DateTime]>]...

You might want to do this instead:

$secpasswd = ConvertTo-SecureString -String "pa$$word1" -AsPlainText -Force
New-ADuser -Name 'johnd' -GivenName'John' -Surname 'Doe' -DisplayName 'John Doe' -AccountPassword $secpasswd
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.