We’ve created a PowerShell script which will reset the password of all users in a specific OU.
I prefer to set unique high-end passwords for all users. If you prefer a more ‘user friendly’ approach simply remove the “Function” and set the $Password variable to something else.
Let me know if you need any help adjusting it.
# Reset Password for a OU - jocha.se
#
Import-Module ActiveDirectory
$OU = "ou=OfficeA,dc=DOMAIN,dc=LOCAL" # Change OU
Function Get-RandomPassword {
$length = 8
$characters = 'abcdefghkmnprstuvwxyzABCDEFGHKLMNPRSTUVWXYZ'
$nonchar = '123456789!$%&?#'
$random = 1..$length | ForEach-Object { Get-Random -Maximum $characters.length }
$random2 = 1..2 | ForEach-Object { Get-Random -Maximum $nonchar.length }
$private:ofs= ""
$ThePassword = [String]$characters[$random] + [String]$nonchar[$random2]
return $ThePassword
}
$Users = (Get-ADUser -filter * -SearchBase $OU | select DisplayName, SamAccountName )
ForEach ($User in $Users) {
$Username = $User.SamAccountName
$DisplayName = $User.DisplayName
$Password = Get-RandomPassword
Write-host $DisplayName / $Username / $Password
Set-ADAccountPassword -id $username -NewPassword (ConvertTo-SecureString -AsPlainText $Password -Force) -WhatIf
}
A very informative stuff that elaborates good points to reset passwords of all users in specific OU.
Since few days ago, I was looking for immediate solution with the same concern while I needed to accomplish this task.
Though, I had completed this task by using an automated solution named Lepide active directory cleaner that is really a very comprehensive tool.
However, I would definitely give a try to this PS in my future environment.
Hey Andresparnova,
Thanks for stopping by. We have developed a custom "AD cleaning" module for PowerShell, much like the Lepide product, but open-source and free.
It does however require some PowerShell knowledge to set up to each specific domain.
Let us know if you need any more assistance with scripting.
Hi I would like to add the option IF account is disabled enabled then change the password.