PowerShell - Reset User passwords from Txt
- Jon Boyette
- Jan 18, 2022
- 1 min read
Rename the below as a ResetPasswordFromTXT.ps1 or similar self named, this takes all listed in the c:\temp\userlist.txt , it resets each with a random generated password that it lists on screen, and the user is prompted to change at login
# Import ActiveDirectory module
Import-module ActiveDirectory
# Grab list of users from a text file.
$ListOfUsers = Get-Content C:\Temp\userlist.txt
foreach ($user in $ListOfUsers) {
#Generate a 15-character random password.
$Password = -join ((33..126) | Get-Random -Count 15 | ForEach-Object { [char]$_ })
#Convert the password to secure string.
$NewPwd = ConvertTo-SecureString $Password -AsPlainText -Force
#Assign the new password to the user.
Set-ADAccountPassword $user -NewPassword $NewPwd -Reset
#Force user to change password at next logon.
Set-ADUser -Identity $user -ChangePasswordAtLogon $true
#Display userid and new password on the console.
Write-Host $user, $Password
}
Comments