Password Reset

This script resets the password for multiple users and sends a notification email (assuming you have a configured SMTP server).

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 = "[email protected]"

# 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 = "[email protected]"
    $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 [email protected] to match your SMTP server settings.

• Replace NewP@ssword123 with a secure password or consider generating unique passwords.

Last updated