• Home
  • PowerShell
  • Changing the Password never expires attribute and expiration date using PowerShell

Changing the Password never expires attribute and expiration date using PowerShell

Step 1: Check if a user’s password is set to "never expire"

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.

Step 2: Disable the Password Never Expire setting

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

Step 3: Set a custom password expiration date

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)}

Step 4: Apply these settings to an entire group

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}

FAQs

1. How do I set a user’s password to "never expire"?

Run the following PowerShell command by replacing username with the actual user’s username.

Set-ADUser -Identity username -PasswordNeverExpires $true

2. How can I reset a user’s password expiry date?

The command below will force the user to reset their password at the next login.

Set-ADUser -Identity username -Replace @{pwdLastSet=0}

3. How do I check if a user’s password is set to "never expire"?

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
 
  • Step 1: Check if a user’s password is set to "never expire"
  • Step 2: Disable the Password Never Expire setting
  • Step 3: Set a custom password expiration date
  • Step 4: Apply these settings to an entire group
  • FAQs

ADSelfService Plus trusted by

A single pane of glass for complete self service password management
Email Download Link