Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

1 Answer 1

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.