Is there any way or method to figure out my mistake to get solution for this command?

191 views Asked by At

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

There are 2 answers

3
Wasif On

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
0
Akshay Chouksey On

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