none
Set-AdAccountPassword RRS feed

  • Question

  • client gave me a csv file with usernames and new passwords. I need to bulk change several hundred users through PowerShell. Not quite sure how to do it. Will something like this work?

    Import-CSV C:\TEMP\... | Foreach {

    Set-ADAccountPassword -Identity $_.UPN -Reset -NewPassword (ConvertTo-SecureString -AsPlainText $_.NEWPW -Force)}

    -------------------------

    I've seen this code, but not quite sure what's going on with it. I guess it assumes that the csv file has two columns (Name,AccountPassword)?? 

    param($file)
    import-module activedirectory
    $Users=import-csv $file
    foreach ($user in $users)
    {
    $PlainTextPassword=[string]$user.accountPassword    
    $NewPassword=ConvertTo-SecureString $PlainTextPassword -AsPlainText -force
        Set-ADAccountPassword -identity $user.Name -Reset -NewPassword $NewPassword -Verbose
    }

    Tuesday, August 30, 2016 9:38 PM

Answers

  • Hi Vegas,

    Please refer to this sample:

    import-module activedirectory
    $users = Import-Csv -Path C:\share\pwd.csv
    foreach($user in $users)
    {
        $PlainTextPassword=[string]$user.accountPassword    
        $NewPassword=ConvertTo-SecureString $PlainTextPassword -AsPlainText -force
         Set-ADAccountPassword -identity "cn=$($user.name),ou=test,dc=corp,dc=contoso,dc=com" -Reset -NewPassword $NewPassword -Verbose
    }
    

    Note: Your password need to meet the password policies.

    Related policies in GPO:

    https://technet.microsoft.com/en-us/library/hh994562(v=ws.11).aspx

    Best regards,

    Andy_Pan


    Please remember to mark the replies as an answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft..com.

    Wednesday, August 31, 2016 3:38 AM
    Moderator

All replies

  • Hi Vegas,

    Please refer to this sample:

    import-module activedirectory
    $users = Import-Csv -Path C:\share\pwd.csv
    foreach($user in $users)
    {
        $PlainTextPassword=[string]$user.accountPassword    
        $NewPassword=ConvertTo-SecureString $PlainTextPassword -AsPlainText -force
         Set-ADAccountPassword -identity "cn=$($user.name),ou=test,dc=corp,dc=contoso,dc=com" -Reset -NewPassword $NewPassword -Verbose
    }
    

    Note: Your password need to meet the password policies.

    Related policies in GPO:

    https://technet.microsoft.com/en-us/library/hh994562(v=ws.11).aspx

    Best regards,

    Andy_Pan


    Please remember to mark the replies as an answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft..com.

    Wednesday, August 31, 2016 3:38 AM
    Moderator
  • Hi Vegas ,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,

    Andy_Pan

    Please remember to mark the replies as an answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft..com.

    Tuesday, September 6, 2016 2:15 AM
    Moderator