How to reset password for multiple users in bulk via powershell

Configurare noua (How To)

Situatie

Below is a PowerShell script to reset passwords for multiple users in bulk:

Solutie

# Path to the CSV file containing user details (e.g., SamAccountName, NewPassword) $csvFilePath = “C:\Path\to\users.csv”

# Import user details from the CSV file

$users = Import-Csv $csvFilePath

# Loop through each user and reset their password

foreach ($user in $users) {

$username = $user.SamAccountName $newPassword = $user.NewPassword

# Check if the user exists

if (Get-ADUser -Filter {SamAccountName -eq $username}) {

# Reset the user’s password

Set-ADAccountPassword -Identity $username -NewPassword (ConvertTo-SecureString -AsPlainText $newPassword -Force) -Reset Write-Host “Password reset for user $username”

}

else {

Write-Host “User $username not found”

}

}

Before running the script, ensure you have a CSV file (e.g., “users.csv”) containing at least two columns: “SamAccountName” and “NewPassword”. Each row in the CSV file should contain the SamAccountName of a user and the corresponding new password to set for that user.

Example CSV file (users.csv):

SamAccountName,NewPassword
user1,NewPass1
user2,NewPass2
user3,NewPass3

Replace “C:\Path\to\users.csv” with the actual path to your CSV file.

This script will read user details from the CSV file, loop through each user, check if the user exists in Active Directory, and reset their password if they exist. If the user does not exist, it will display a message indicating that the user was not found.

Tip solutie

Permanent

Voteaza

(2 din 13 persoane apreciaza acest articol)

Despre Autor

Leave A Comment?