Resetting AD passwords using PowerShell

Step 1: Connect to Active Directory

Ensure you are connected to AD before running the script. This loads the AD module required for user management.

Import-Module ActiveDirectory

Step 2: Create a password reset function

Define a script to handle password resets securely. This function resets passwords for specified users.

function Reset-UserPassword {
param (
[string]$Username,
[string]$NewPassword
)

$SecurePassword = ConvertTo-SecureString $NewPassword -AsPlainText -Force
Set-ADAccountPassword -Identity $Username -NewPassword $SecurePassword -Reset
Write-Host "Password reset successfully for $Username"
}

Step 3: Allow users to reset their passwords

Create a simple user prompt to accept input. This script prompts users for their username and new password.

$Username = Read-Host "Enter your username"
$NewPassword = Read-Host "Enter new password" -AsSecureString

Reset-UserPassword -Username $Username -NewPassword (ConvertFrom-SecureString $NewPassword)

Step 4: Automate the process

Run this script as a self-service reset tool. This script automates self-service password resets by running the script at startup.

$trigger = New-ScheduledTaskTrigger -AtStartup
$action = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "-File C:\Scripts\SelfServiceReset.ps1"
Register-ScheduledTask -TaskName "SelfServiceReset" -Trigger $trigger -Action $action -User "SYSTEM"

FAQs

1. How does self-service password reset work in AD?

Users can reset passwords without IT intervention using an automated PowerShell script.

2. Can I allow only specific users to reset their passwords?

Yes, you can use group-based access control to restrict access to specific users.

3. How do I check password reset attempts?

Use the script below to get password reset attempt event logs:

Get-EventLog -LogName Security -InstanceId 4724
 
  • Step 1: Connect to Active Directory
  • Step 2: Create a password reset function
  • Step 3: Allow users to reset their passwords
  • Step 4: Automate the process
  • FAQs

ADSelfService Plus trusted by

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