The script will reset password for users in specified OUs, or in a given CSV file.
IT Administrators may want to reset password for a large number of users in company. It will cost too much time to set new password one by one. Sometimes the new password should be a random password and different for every user. It’s easy to make mistake in manually way.
This module file contains three advanced function, Set-OSCADAccountPassword. You can use this script in following ways:
1. Open Powershell in “Run as administrator” mode.
2. Run command Import-Module “c:\ResetPassword.psm1” to import this module file.
Note Assuming you downloaded this file in the drive C directly.
Example 01: How to displays help about the Set-OSCADAccountPassword function
To display help about theSet-OSCADAccountPassword function, run the following command:
Get-Help Set-OSCADAccountPassword -Full
Example 02: How to reset password for specified users.
To reset password for specified users, should put these user’s SamAccountName in a CSV file, then run the following command:
Set-OSCADAccountPassword -path “c:\Userlist.csv”
Note first, you need to prepare a CSV file,its format appears as below. One user per line. The “Password” column is optional, if you leave it empty, this command will help you to generate a random password with 10 characters, 7 char are alphanumeric, the rest are NONalphanumeric. Both format A and format B are allowed
|SamAccountName of user, who should reset password||The new password you want to set|
Format A Format B
Before run this command, prepare a CSV file show as below:
Then run the command: Set-OSCADAccountPassword -path “c:\Userlist.csv”
Finally, a CSV file will be created on “C:\”, which contains user SamAccountName and new password.
Example 03: How to reset password for all users in specified OUs and their sub OU
To reset password for all users in specified OUs and their sub OU, run the following command:
Set-OSCADAccountPassword –OrganizationalUnit “testou1”, “testou2” -Recurse
Note AD structure show as below
Example 04: How to reset password to “P@Ssw0rd” for all users in specified OU, and indicate the path of result CSV file.
To reset password to “P@Ssw0rd” for all users in OU “TestOU” and indicate the path of CSV file to “c:\report\result.csv”, run the following command:
Set-OSCADAccountPassword –OrganizationalUnit “testou” -Password “P@Ssw0rd” –CSVPath “c:\report\result.csv”