Hi.
im really new at PS and trying to create a command/script that prompt me ech time for user account password when i run below command.
Running PS 5 on Windows 2012 R2
Like
New-ADUser -Name sccmadmin -GivenName sccm -surname admin -DisplayName configadmin -Path “ou=Users,ou=cgmt,DC=cgmt,dc=int” | Set-ADAccountPassword SCCMAdmin | -AccountPassword (Read-Host -AsSecureString “AccountPassword”)
Get error
-AccountPassword : The term ‘-AccountPassword’ 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:160
… ,dc=int" | Set-ADAccountPassword SCCMAdmin | -AccountPassword (Read-H …
~~~~~~~~~~~~~~~~
CategoryInfo : ObjectNotFound: (-AccountPassword:String) , CommandNotFoundException
FullyQualifiedErrorId : CommandNotFoundException
donj
September 15, 2015, 7:17pm
2
Well, Read-Host will work, as you’ve got it, right?
Please see my added error message
donj
September 15, 2015, 7:42pm
4
That’s a syntax error.
Set-ADAccountPassword SCCMAdmin | -AccountPassword (Read-Host -AsSecureString "AccountPassword")
You’ve put a pipe character in the middle of the command, which cases the shell to try and treat -AccountPassword as a new command, which it isn’t. Remove the pipe character.
Run it
New-ADUser -Name sccmadmin -GivenName sccm -surname admin -DisplayName configadmin -Path “ou=Users,ou=cgmt,DC=cgmt,dc=int” | Set-ADAccountPassword SCCMAdmin -AccountPassword (Read-Host -AsSecureString “AccountPassword”)
Get error
Set-ADAccountPassword : A parameter cannot be found that matches parameter name ‘AccountPassword’.
At line:1 char:158
… mt,dc=int" | Set-ADAccountPassword SCCMAdmin -AccountPassword (Read-H …
~~~~~~~~~~~~~~~~
CategoryInfo : InvalidArgument: ( [Set-ADAccountPassword], ParameterBindingException
FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.ActiveDirectory.Management.Commands.SetADAccountPassword
Set-ADAccountPassword doesn’t have -AccountPassword parameter
http://go.microsoft.com/fwlink/?LinkID=144999
it have -NewPassword (and [hint] -Reset switch)
i solve it with a set-variabel -name
New-ADUser -Name sccmadmin -GivenName sccm -surname admin -DisplayName configadmin -Path “ou=Users,ou=cgmt,DC=cgmt,dc=int” | Set-ADAccountPassword SCCMAdmin | Set-Variable -Name AccountPassword (Read-Host -AsSecureString “AccountPassword”)