Direct Inward Dialing: +1 408 916 9393
An Active Directory (AD) account with no expiration date remains valid until it is disabled, deleted, or otherwise restricted. Finding these accounts is a routine security and auditing task since a forgotten, non-expiring account, especially one that's stale but still enabled, can pose a security risk. This guide explains how to find AD accounts that never expire using PowerShell, Active Directory Users and Computers (ADUC), and ManageEngine ADManager Plus.
Import-Module ActiveDirectory
There's no dedicated cmdlet for non-expiring accounts, so you use Get-ADUser with a filter on the AccountExpirationDate attribute. An account that never expires has no value for this attribute, so you filter for the accounts where the value is not present. Because AccountExpirationDate isn't a default property, request it with -Properties:
Get-ADUser -Filter "AccountExpirationDate -notlike '*'" -Properties AccountExpirationDate |
Select-Object Name, SamAccountName, Enabled
The -notlike '*' test matches accounts where the expiration date has no value, which is every account set to never expire. The result lists each one with its name, its logon name, and whether it's enabled.
A non-expiring account that's also disabled is a lower priority, so for a security review, you usually want only the enabled ones. Add an Enabled -eq $true condition to the filter:
Get-ADUser -Filter "AccountExpirationDate -notlike '*' -and Enabled -eq '$true'" `
-Properties AccountExpirationDate |
Select-Object Name, SamAccountName
This narrows the list to enabled accounts that never expire: the ones that actually keep access open. To improve performance in a large directory, scope the search to a single OU with -SearchBase and provide the OU's distinguished name:
Get-ADUser -Filter "AccountExpirationDate -notlike '*'" -SearchBase "OU=Staff,DC=corp,DC=com" `
-Properties AccountExpirationDate | Select-Object Name, SamAccountName
The same search can be written with -LDAPFilter, which some administrators prefer. In LDAP, an account that never expires has accountExpires set to 0 or to the maximum value (9223372036854775807), so the filter matches both:
Get-ADUser -LDAPFilter "(|(accountExpires=0)(accountExpires=9223372036854775807))" |
Select-Object Name, SamAccountName
Both approaches return the same accounts; the PowerShell filter is more readable, while the LDAP filter maps directly to the underlying accountExpires attribute.
To share the list or retain it for an audit, pipe the results to Export-Csv, selecting the columns you want and adding -NoTypeInformation and -Encoding UTF8:
Get-ADUser -Filter "AccountExpirationDate -notlike '*'" -Properties AccountExpirationDate, LastLogonDate |
Select-Object Name, SamAccountName, Enabled, LastLogonDate |
Export-Csv -Path "C:\Reports\Never-Expire-Accounts.csv" -NoTypeInformation -Encoding UTF8
| Parameter or cmdlet | Description |
|---|---|
| Get-ADUser | Retrieves user objects—there is no dedicated never-expire cmdlet |
| -Filter | Filters users on the server side—AccountExpirationDate -notlike ''* matches non-expiring accounts |
| -Properties | Requests AccountExpirationDate and other non-default attributes |
| -LDAPFilter | An alternative filter on the raw accountExpires attribute (0 or the maximum value) |
| -SearchBase | Scopes the search to a specific OU by the distinguished name |
| Select-Object | Chooses the columns to return |
| Export-Csv | Writes the results to a CSV file |
ADUC has no built-in filter or view for accounts that never expire, so you can’t find them the way you would find locked or disabled accounts. The work-around is to create a Saved Query with a custom LDAP filter, which lists the matching accounts in the console.
ManageEngine ADManager Plus is a unified AD, Exchange, and Microsoft 365 management and reporting tool with a prebuilt report for non-expiring accounts.
From the report, you can enable, disable, delete, or move the listed accounts or set an expiration date on them using the built-in management actions.
ADManager Plus simplifies management and reporting across AD, Microsoft 365, and Exchange through a single console, reducing the need for scripts and individual queries.
Before a security or compliance review, you need every account with no expiration date to be exported for the auditor. Use a filter on AccountExpirationDate and export the result:
Get-ADUser -Filter "AccountExpirationDate -notlike '*'" -Properties AccountExpirationDate, LastLogonDate |
Select-Object Name, SamAccountName, Enabled, LastLogonDate |
Export-Csv "C:\Reports\Never-Expire-Audit.csv" -NoTypeInformation -Encoding UTF8
For cleanups, the accounts that matter most are the ones that never expire and haven't been used in a long time. Combine the expiration filter with a last logon check:
$cutoff = (Get-Date).AddDays(-90)
Get-ADUser -Filter "AccountExpirationDate -notlike '*' -and Enabled -eq '$true'" `
-Properties AccountExpirationDate, LastLogonDate |
Where-Object { $_.LastLogonDate -lt $cutoff } |
Select-Object Name, SamAccountName, LastLogonDate
Use Automation to disable or remove the matching accounts from the Account Never Expires Users or Inactive Users report.
Service accounts are often set to never expire on purpose, so a review usually means separating them from regular user accounts, commonly by using the OU where they reside or by following a naming convention. Scope the search to the service account OU:
Get-ADUser -Filter "AccountExpirationDate -notlike '*'" `
-SearchBase "OU=ServiceAccounts,DC=corp,DC=com" -Properties AccountExpirationDate |
Select-Object Name, SamAccountName, Enabled
Run the Account Never Expires Users report scoped to the service account OU to list only those accounts and keep them separate from the user account review.
They're separate settings. An account that never expires has no value in AccountExpirationDate, so the account stays usable indefinitely. A password that never expires has the PasswordNeverExpires flag set, so the password is exempt from the expiration policy while the account itself can still expire. This page covers the former; to find the latter, use a filter on PasswordNeverExpires instead.
The main risk is persistent access that outlives its purpose. A non-expiring account for a departed employee, a finished contractor, or a retired service account stays usable until someone notices and disables it, and a stale but enabled account like this can provide a foothold for an attacker. The more non-expiring accounts that accumulate unreviewed, the larger the standing attack surface, which is why listing and auditing them regularly is a basic security practice.
Use the Set-ADAccountExpiration cmdlet with the account and the date—for example:
Set-ADAccountExpiration -Identity "jsmith" -DateTime "12/31/2026"