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 $secpasswdI 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?
1 Answer
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 1