The list of users for reset should be stored in a CSV file (reset_users.csv) with the Username header.
# SMTP server details
$smtpServer = "smtp.yourdomain.com"
$fromEmail = "admin@yourdomain.com"
# Import users from a CSV file
$users = Import-Csv -Path "C:\Path\To\reset_users.csv"
foreach ($user in $users) {
$samAccountName = $user.Username
$newPassword = ConvertTo-SecureString "NewP@ssword123" -AsPlainText -Force
# Reset password
Set-ADAccountPassword -Identity $samAccountName -NewPassword $newPassword -Reset
Unlock-ADAccount -Identity $samAccountName
# Send notification
$toEmail = "$samAccountName@yourdomain.com"
$subject = "Password Reset Notification"
$body = "Your password has been reset. Your new password is: NewP@ssword123"
Send-MailMessage -From $fromEmail -To $toEmail -Subject $subject -Body $body -SmtpServer $smtpServer
Write-Host "Password reset for $samAccountName and email sent."
}
• Update smtp.yourdomain.com and admin@yourdomain.com to match your SMTP server settings.
• Replace NewP@ssword123 with a secure password or consider generating unique passwords.