Q. How can I easily change the password of many users?
A. The script below can be used to change the password and unlock the account of every user based on their SAMAccountName but could be changed based on user objects directly easily.
$securePassword = ConvertTo-SecureString "Pa55word!123" -AsPlainText -Force
foreach($samname in $samlist)
{
$userobj = Get-ADUser -LDAPFilter "(SAMAccountName=$samname)"
if ($userobj -ne $null)
{
$userobj | Set-Aduser -ChangePasswordAtLogon $false
$userobj | Set-ADAccountPassword -NewPassword $securePassword -Reset
$userobj | Unlock-ADAccount
}
}
0 comments
Hide comments