How to set AD user passwords to never expire

While PowerShell allows you to set passwords to never expire, this practice should be limited to exceptional cases, like service accounts or legacy applications. Having users in your Active Directory (AD) with perpetual passwords can expose your organization to brute-force attacks and audit failures. Once you identify AD users with non-expiring passwords, enabling expiration will urge them to change passwords periodically, thereby reducing risks and ensuring compliance.

Configuring password expiration for AD users

The PasswordNeverExpires property determines whether a user's password follows the domain's policy. Setting it to False ensures the password will expire according to the domain's policy. In rare cases like service accounts, hardcoded credentials, or legacy apps that may break if passwords change, you may need to set PasswordNeverExpires to True so the password never expires.

Windows PowerShell

Prerequisites

Import the AD module (if not done already) using this command:

Import-Module ActiveDirectory

Using the Set-ADUser cmdlet to configure password expiration

Run the commands below to enable password expiration. If you'd like to set the password to never expire, replace $false with $true.

Get-ADUser -Filter 'PasswordNeverExpires -eq $true' -Properties PasswordNeverExpires |
Select-Object Name, SamAccountName, PasswordNeverExpires
  • Single AD user: (replace username with the user's login name)
    Set-ADUser -Identity "username" -PasswordNeverExpires $false
  • All users in an OU: (replace OU=Users,DC=domain,DC=com with your OU's distinguished name)
    Get-ADUser -Filter * -SearchBase "OU=Users,DC=domain,DC=com" |
    ForEach-Object { Set-ADUser $_ -PasswordNeverExpires $false }
  • All users in a domain:
    Get-ADUser -Filter * | ForEach-Object {
    Set-ADUser $_ -PasswordNeverExpires $false }
ADManager Plus
  1. Navigate to Management > User Management > Bulk User Modification Reset Password.
  2. Under Password options in the Password never expires drop-down,
    • Select Yes to disable password expiration.
    • Select No to enable password expiration.
  3. Select the domain and click Add OUs to select your preferred OUs.
  4. Enter the name of the user that you'd like to configure password expiration for. To add multiple users, select CSV Import and add a CSV file containing the user list.
  5. Click Go. Confirm the user list on the following page and click Apply.

Note: To list users in your AD whose passwords are set to never expire, follow these steps.

Example use cases and scripts for password expiration tasks

Example 1: Set password to never expire for a single user

Set-ADUser -Identity "james" -PasswordNeverExpires $true

Example 2: Set password to never expire for all users in an OU

Get-ADUser -Filter * -SearchBase "OU=Users,DC=domain,DC=com" |
ForEach-Object { Set-ADUser $_ -PasswordNeverExpires $true }

Example 3: Enable password expiration for all members of a specific AD Group

$GroupName = "Audit Non-Compliant Accounts"
Get-ADGroupMember -Identity $GroupName |
Get-ADUser |
ForEach-Object {
Set-ADUser -Identity $_ -PasswordNeverExpires $false
Write-Host "Set password for group member $($_.SamAccountName) to expire according to policy."
}

Example 4: Enable password expiration for a list of users from a CSV file

$UserList = Import-Csv -Path "C:\Temp\UsersToExpire.csv"
foreach ($User in $UserList) {
Set-ADUser -Identity $User.SamAccountName -PasswordNeverExpires $false
Write-Host "Set password for user $($User.SamAccountName) to expire according to policy."
}

Supported parameters

The following are essential parameters to perform password expiration tasks in PowerShell:

Parameter Description
-Filter Finds users matching password policy conditions.
-Properties Displays extended properties (PasswordNeverExpires).
-SearchBase Limits scope to an OU or container.
-Identity Specifies the account to modify.
-PasswordNeverExpires Enables or disables password expiration for target user.
-Path Output file path for exported report.

Limitations of using PowerShell to perform password expiration operations

  • Requires exact distinguished names and user identifiers, which can complicate bulk updates.
  • Scripting errors can affect large groups if not carefully filtered.
  • Lacks integrated scheduling, alerting, or rollback features; all actions are manual.
  • Permissions must be delegated appropriately for technicians running scripts.

How ADManager Plus helps manage user passwords and other AD objects

ADManager Plus is a web-based AD and Microsoft Entra ID management and reporting tool that simplifies AD password management and more from a centralized interface:

Simplify AD management and reporting with ADManager Plus

FAQs

To disable password expiration for a local user in PowerShell, you can use the Set-LocalUser cmdlet. Open PowerShell as an administrator and run the following command by replacing <username> with the actual name of the local user account:

Set-LocalUser -Name "<username>" -PasswordNeverExpires $true

Historically, organizations were discouraged from setting passwords to never expire, as doing so could increase the risk of long-term compromise and non-compliance with security standards. However, password expiration can sometimes backfire, as users may choose simpler passwords. In environments that rely on service accounts or legacy applications, non-expiring passwords may be necessary to avoid disruptions, but they should be safeguarded with strong complexity and monitoring.

Current cybersecurity best practices recommend setting strong passwords with a significant length and then setting them to never expire. This approach is more effective when combined with other security measures, such as multi-factor authentication.

Ultimately, the key is to balance security with practicality, using extra safeguards when passwords can’t expire.

The one-stop solution to Active Directory Management and Reporting
Email Download Link