The two scripts below can be used to set the Password never expires attribute to true and change the password expiration date in Active Directory (AD).
To set the Password never expires attribute for AD users:
$User = (Read-Host -Prompt "Username")
Set-ADUser -Identity $User -PasswordNeverExpires $true 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
ADSelfService Plus is an integrated AD self-service password management and single sign-on solution that provides a customizable password expiration notification scheduler. Using this feature, you can customize:
To learn more about ADSelfService Plus, click here.
Run the following command to check the PasswordNeverExpires attribute.
Get-ADUser -Identity "username" -Properties "PasswordNeverExpires" Note: This returns True if the password never expires, False otherwise.
To enforce password expiry for a user, set PasswordNeverExpires to $false. This will require the user to change their password periodically.
Set-ADUser -Identity "username" -PasswordNeverExpires $false Modify the expiration date for a specific user. This forces the password to expire in 30 days.
Set-ADUser -Identity "username" -Replace @{"msDS-UserPasswordExpiryTimeComputed" = [datetime]::Now.AddDays(30)} Update all users in a specific group using the command below. This loops through all users in the group and applies the change.
Get-ADGroupMember -Identity "GroupName" | ForEach-Object {Set-ADUser -Identity $_.SamAccountName -PasswordNeverExpires $false}Run the following PowerShell command by replacing username with the actual user’s username.
Set-ADUser -Identity username -PasswordNeverExpires $trueThe command below will force the user to reset their password at the next login.
Set-ADUser -Identity username -Replace @{pwdLastSet=0} Check if a user’s password is set to "never expire" by running the command below. This will return True if the password never expires.
Get-ADUser -Identity username -Properties PasswordNeverExpires | Select Name, PasswordNeverExpires