Powershell – Bulk User Password Resets

Simple Powershell script to bulk reset passwords from a text file containing one user per line. This makes use of the Get-ADUser, Set-ADUser, and Set-ADAccountPassword Powershell active directory cmdlets.

# import the AD module
if (-not (Get-Module ActiveDirectory)){
	Import-Module ActiveDirectory -ErrorAction Stop            

# set new default password
$password = ConvertTo-SecureString -AsPlainText "Password01" -Force  

# get list of account names (1 per line)
$list = Get-Content -Path c:\scripts\users.txt

# loop through the list
ForEach ($u in $list) {

	if ( -not (Get-ADUser -LDAPFilter "(sAMAccountName=$u)")) { 
		Write-Host "Can't find $u" 
	else { 
		$user = Get-ADUser -Identity $u
		$user | Set-ADAccountPassword -NewPassword $password -Reset
		$user | Set-AdUser -ChangePasswordAtLogon $true
		Write-Host "changed password for $u"

One thought on “Powershell – Bulk User Password Resets”

  1. Hello, thanks for the script, but it errors. I would love to get this working. Can you help?

    Can’t find “john.Smith”
    et-ADUser : The search filter cannot be recognized
    At line:1 char:33
    + ForEach ($u in $list) {if(-not (Get-ADUser -LDAPFilter “(sAMAccountName=$u)”)) { …
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [Get-ADUser], ADException
    + FullyQualifiedErrorId : ActiveDirectoryServer:8254,Microsoft.ActiveDirectory.Management.Commands.GetADUser.

Leave a Reply