← script library
Retrieve and Reset User Passwords in Active Directory
Active DirectoryJanuary 6, 2025
Managing user passwords in Active Directory is essential for ensuring security and compliance. This PowerShell script provides administrators with the capability to retrieve user passwords (in a secure manner) and reset them if needed. This can significantly enhance your ability to manage user accounts effectively, especially during security audits and compliance checks. At ServerEngine, we design powerful tools to support your IT management needs.
powershell
Import-Module ActiveDirectory
function Get-ADUserPasswords {
param (
[string]$username
)
try {
$user = Get-ADUser -Identity $username -Properties SamAccountName, UserPrincipalName
Write-Host "User Account Information:"
Write-Host "SamAccountName: $($user.SamAccountName)"
Write-Host "UserPrincipalName: $($user.UserPrincipalName)"
Write-Host "Note: Password cannot be retrieved for security reasons."
} catch {
Write-Host "ERROR: User not found. Error: $_"
}
}
function Reset-ADUserPassword {
param (
[string]$username,
[string]$newPassword
)
$securePassword = ConvertTo-SecureString $newPassword -AsPlainText -Force
try {
Set-ADAccountPassword -Identity $username -NewPassword $securePassword
Write-Host "Password for user $username has been successfully reset."
} catch {
Write-Host "ERROR: Could not reset password for user $username. Error: $_"
}
}
Get-ADUserPasswords -username "jdoe"
Reset-ADUserPassword -username "jdoe" -newPassword "NewP@ssword123!"Run it across your fleet
This script runs as-is on a single host. Paste it into ServerEngine to schedule it, run it on a whole server group in parallel, and keep the credentials out of the file — see the scripts documentation and the credential store.
More in Active Directory
Active Directory User Onboarding with PowerShell
2026-08-17Active Directory User Offboarding with PowerShell
2026-08-17Disable an Active Directory User with PowerShell
2026-08-17Enable an Active Directory User with PowerShell
2026-08-17Unlock an Active Directory Account with PowerShell
2026-08-17Reset an Active Directory Password with PowerShell
2026-08-17Ready when you are.
Try ServerEngine free for 7 days.