How to reset an AD user password and force to change at logon using PowerShell

preview_player
Показать описание
Shows on how to reset an AD user account's password and force the user to change the password next time the user log in.
Basic Script:
Set-ADAccountPassword -Identity $username -Reset -NewPassword (ConvertTo-SecureString -AsPlainText "$password" -force) -Confirm:$false
Set-ADUser -PasswordNeverExpires $true -ChangePasswordAtLogon $false -Identity $username -Confirm:$false
Script to take the input values and change the password:

$username=Read-Host -Prompt "Enter User Name for Password reset"
$password=Read-Host -Prompt "Enter a Password"

Set-ADAccountPassword -Identity $username -Reset -NewPassword (ConvertTo-SecureString -AsPlainText "$password" -force) -Confirm:$false
Set-ADUser -PasswordNeverExpires $true -ChangePasswordAtLogon $false -Identity $username -Confirm:$false

Write-host $username 'Password has been reset and set to change at Next Logon' -F green
Get-aduser -identity $username -properties department, mail, title, description, PasswordNeverExpires, PasswordLastSet
Рекомендации по теме
Комментарии
Автор

Is Their a way to prompt user and give them a warning that the password will expire before forcing pw change ?

Change