How to change the Password never expires attribute and set a password expiration date using PowerShell

Reference:

https://www.manageengine.com/products/self-service-password/powershell/how-to-change-password-never-expires-attribute-and-expiration-date.html

Set the Password never expires attribute

To set the Password never expires attribute for AD users:

$User = (Read-Host -Prompt “Username")
Set-ADUser -Identity $User -PasswordNeverExpires $true

Set the password expiration date

You can extend the validity of an AD password by setting the pwdlastset attribute to -1, which sets the value of the attribute to the current date and time.

$Username = (Read-Host -Prompt “Username")
$User = Get-ADUser $Username -Properties pwdlastset
$User.pwdlastset = 0
Set-ADUser -Instance $User
$User.pwdlastset = -1
Set-ADUser -Instance $User

發表留言

在WordPress.com寫網誌.

向上 ↑