Reset password for all specified users
Introduction
The script will reset password for users in specified OUs, or in a given CSV file.
Scenarios
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.
Script
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.
Here are some code snippets for your references. To get the complete script sample, please click the download button at the beginning of this page.
PowerShell
Edit|Remove
powershell
Write-Progress -Activity $ProgressTitle -Status "Processing" -CurrentOperation $Identity -PercentComplete ($counter / ($Userlist.Count) * 100)
#reset password
Set-AdaccountPassword -Identity $Identity -Reset -NewPassword (ConvertTo-SecureString -AsPlainText $NewPassword -Force)
#export a csv file
$Account = New-Object PSObject
$Account | Add-Member -MemberType NoteProperty -Name "Identity" -Value $Identity
$Account | Add-Member -MemberType NoteProperty -Name "NewPassword" -Value $NewPassword
$result+=$Account
Write-Progress-Activity $ProgressTitle-Status "Processing"-CurrentOperation $Identity-PercentComplete ($counter/ ($Userlist.Count) * 100)
#reset password
Set-AdaccountPassword -Identity $Identity-Reset -NewPassword (ConvertTo-SecureString-AsPlainText $NewPassword-Force)
#export a csv file $Account = New-Object PSObject
$Account|Add-Member-MemberType NoteProperty -Name "Identity"-Value $Identity$Account|Add-Member-MemberType NoteProperty -Name "NewPassword"-Value $NewPassword$result+=$Account
Examples
Example 01: How to displays help about the Set-OSCADAccountPassword function
To display help about the Set-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
|
Password
|
|
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.

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”

Additional Resources
Technical Resources:
Windows PowerShell Advanced Function
Get-ADOrganizationalUnit
Get-ADAccountPassword
Get-ADUser
Export-Csv