Prompt for Password - New User

This topic contains 6 replies, has 3 voices, and was last updated by  Roger Ohlsson 2 years, 2 months ago.

  • Author
    Posts
  • #29805

    Roger Ohlsson
    Participant

    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

  • #29807

    Don Jones
    Keymaster

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

  • #29808

    Roger Ohlsson
    Participant

    Please see my added error message

  • #29809

    Don Jones
    Keymaster

    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.

  • #29810

    Roger Ohlsson
    Participant

    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

  • #29811

    Max Kozlov
    Participant

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

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

  • #29812

    Roger Ohlsson
    Participant

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

You must be logged in to reply to this topic.