none
Bulk change of AD user passwords with Powershell script

    Question

  • Hi

    I'm looking to reset in bulk AD user account passwords.  I have this script:

    #
    # Script: ResetPwd.ps1
    # Description: Reset the password for bulk number of users, and 
    # set the property to change passwrod required at next logon
    #
    # Written by: Anand Venkatachalapathy
    #
    
    Import-Module ActiveDirectory
    
    # Set the default password
    $password = ConvertTo-SecureString -AsPlainText “AwesomeP@ssw0rd” -Force 
     
    # Get the list of accounts from the file on file
    # List the user names one per line
    $users = Get-Content -Path c:\MyScripts\UserList.txt
     
    ForEach ($user in $users) 
    {
        # Set the default password for the current account
        Get-ADUser $user | Set-ADAccountPassword -NewPassword $password -Reset
        
        #If you need to set the property “Change password at next logon”, 
        #leave the next alone. If not, comment the next line
        Get-ADUser $user | Set-AdUser -ChangePasswordAtLogon $true
        
        Write-Host “Password has been reset for the user: $user”
    }
    
    # ————- End ———–

    Credit: http://anandthearchitect.com/2014/02/27/active-directory-bulk-user-password-reset-by-powershell/

    This works, however it only lets me set each password to be the same. I'd like to have a second column in a source .csv which lists a unique password per user and have the script change the password as per the file.  Can anyone assist with the necessary changes to the above?  My experience with Powershell is very limited.

    Any assistance is very much appreciated.

    Paul


    Tuesday, December 09, 2014 11:06 AM

Answers

  • Hi STScripter

    I really appreciate your reply, but I was directed by another source to this page:

    https://gallery.technet.microsoft.com/scriptcenter/Reset-password-for-all-412fbc72#content

    This worked perfectly for me.  No doubt your suggestion would have been great as well.

    Thanks for taking the time to reply anyway.

    Paul


    • Marked as answer by Paul Tulloch Thursday, December 11, 2014 3:25 PM
    • Edited by Paul Tulloch Thursday, December 11, 2014 3:25 PM
    Thursday, December 11, 2014 9:57 AM

All replies

  • Hi ,

    I assume you added 2 column in a csv. one is SamAccountName,Password

     

    
    Import-Module ActiveDirectory
    
    # Set the default password
    
     
    # Get the list of accounts from the file on file
    # List the user names one per line
    $users = Import-Csv -Path D:\ser.csv
     
    ForEach ($user in $users) 
    {
        # Set the default password for the current account
        Set-ADAccountPassword $_.samaccountname -NewPassword $_.password -Reset
        
        #If you need to set the property “Change password at next logon”, 
        #leave the next alone. If not, comment the next line
        Get-ADUser $user | Set-AdUser -ChangePasswordAtLogon $true
        
        Write-Host Password has been reset for the user: $user
    }
    
    • Proposed as answer by STscripter Thursday, December 11, 2014 11:02 AM
    Tuesday, December 09, 2014 2:03 PM
  • Thanks very much for your reply STscripter.  I will give this a go.

    Paul

    Tuesday, December 09, 2014 3:29 PM
  • hey Paul,

    what is update?

    if this help please mark this as answer and vote

    thanks,

     

    Wednesday, December 10, 2014 5:40 AM
  • $_.password has to be converted to SecureString

    ...

    Set-ADAccountPassword $_.samaccountname -NewPassword (ConvertTo-SecureString $_.password -AsPlainText -force) -Reset
    ...

    Wednesday, December 10, 2014 8:03 AM
  • Hi STScripter

    I really appreciate your reply, but I was directed by another source to this page:

    https://gallery.technet.microsoft.com/scriptcenter/Reset-password-for-all-412fbc72#content

    This worked perfectly for me.  No doubt your suggestion would have been great as well.

    Thanks for taking the time to reply anyway.

    Paul


    • Marked as answer by Paul Tulloch Thursday, December 11, 2014 3:25 PM
    • Edited by Paul Tulloch Thursday, December 11, 2014 3:25 PM
    Thursday, December 11, 2014 9:57 AM
  • well nice to hear that..

    can you mark this thread as answer ?

    so , we can close this

    Thanks,

    Thursday, December 11, 2014 11:02 AM