Author Posts

September 16, 2015 at 12:44 am

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

September 16, 2015 at 12:47 am

Well, Read-Host will work, as you've got it, right?

September 16, 2015 at 12:56 am

Please see my added error message

September 16, 2015 at 1:12 am

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.

September 16, 2015 at 2:05 am

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

September 16, 2015 at 2:17 am

Set-ADAccountPassword doesn't have -AccountPassword parameter
http://go.microsoft.com/fwlink/?LinkID=144999

it have -NewPassword (and [hint] -Reset switch)

September 16, 2015 at 2:26 am

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")