0
votes

I type this Powershell command

PS C:\Users\User>  new-aduser -name "Tracy Jones" -givenname "Tracy" -surname "Jones" -samaccountname "tjones" userprincipalname "[email protected]" -path "ou=marketing,dc=abc,dc=com" -accountpassword(-Read-Host -assecurestring "type password for user") -enables $true

It shows me this kind of error message:

-Read-Host : The term '-Read-Host' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

At line:1 char:184

  • ... path "ou=marketing,dc=abc,dc=com" -accountpassword(-Read-Host -assecu ...

  •                                                    ~~~~~~~~~~
    
    • CategoryInfo : ObjectNotFound: (-Read-Host:String) [], CommandNotFoundException

    • FullyQualifiedErrorId : CommandNotFoundException

2
You probably want to add a space after account password and remove the dash infront of Read-Host. But I'm not sure, if calling Read-Host this way is even supported. Maybe you'll have to read the password first and call new-aduser in a second stepderpirscher

2 Answers

0
votes

$passvalue = Read-Host -assecurestring "type password for user". Take the password in a variable then use it as the value for -accountpassword parameter.

0
votes

You can try this:

$pass=Read-Host -Prompt "Type password for user" -AsSecureString -Force
$user=@{
Name="Tracy Jones" 
givenname="Tracy" 
surname="Jones"
samaccountname="tjones" 
userprincipalname="[email protected]"
path="ou=marketing,dc=abc,dc=com"
accountpassword=$pass
enabled=$true
}
new-aduser @user
  • Read-Host in separate variable and statement.
  • Enables corrected to Enabled
  • Done splatting for long cmdlet