Automating password reset using PowerShell

Step 1: Identify users needing a password reset

The script below lists users who haven’t changed passwords in 90 days.

$users = Get-ADUser -Filter {PasswordLastSet -lt (Get-Date).AddDays(-90)} -Properties PasswordLastSet

Step 2: Reset password for users

Run the script below to automatically reset passwords for all identified users. This resets passwords to NewPassword123.

foreach ($user in $users) {
$newPassword = ConvertTo-SecureString "NewPassword123!" -AsPlainText -Force
Set-ADAccountPassword -Identity $user.SamAccountName -NewPassword $newPassword -Reset
}

Step 3: Force users to change password at next login

Ensure users update their passwords with a prompt to set a new password at the next login.

foreach ($user in $users) {
Set-ADUser -Identity $user.SamAccountName -ChangePasswordAtLogon $true
}

Step 4: Notify users about their reset passwords

Send email alerts to users about the reset.

foreach ($user in $users) {
Send-MailMessage -To $user.EmailAddress -From "admin@yourdomain.com" -Subject "Password Reset" -Body "Your password has been reset. Please update it upon your next login."
}

FAQs

1. How can I reset a user's password using PowerShell?

Reset a user's password using the script below. Replace "NewPass@123" with the new password.

Set-ADAccountPassword -Identity username -NewPassword (ConvertTo-SecureString "NewPass@123" -AsPlainText -Force) -Reset

2. How do I force the user to change their password at the next login?

Force the user to change their password using the script below.

Set-ADUser -Identity username -ChangePasswordAtLogon $true

3. Can I reset passwords for multiple users in bulk?

Yes, use a CSV file and script automation to reset passwords for multiple users in bulk.

 
  • Step 1: Identify users needing a password reset
  • Step 2: Reset password for users
  • Step 3: Force users to change password at next login
  • Step 4: Notify users about their reset passwords
  • FAQs

ADSelfService Plus trusted by

A single pane of glass for complete self service password management
Email Download Link