Support
 
Phone Live Chat
 
Support
 
US: +1 888 720 9500
 
Intl: +1 925 924 9500
Aus: +1 800 631 268
UK: 0800 028 6590
CN: +86 400 660 8680

Direct Inward Dialing: +1 408 916 9393

 
 
 
 
 

How to find AD accounts that never expire using PowerShell

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.

 
  • PowerShell
  • ADUC
  • ADManager Plus
  • Troubleshooting
  • Why ADManager Plus
  • Real-world use cases
  • FAQ
 

How to find AD accounts that never expire using PowerShell

Prerequisites

  • Permissions: You need read access to the user objects you're querying, which a standard domain account generally has.
  • Tools: The Get-ADUser cmdlet comes with the AD module for Windows PowerShell, which is part of Remote Server Administration Tools (RSAT). Import it before querying; on a domain controller it's present by default:
    Import-Module ActiveDirectory

List accounts with no expiration date

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.

Exclude disabled accounts to focus on active risks

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

Use an LDAP filter as an alternative

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.

Export the list to a CSV

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

Supported parameters

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

Limitations of using PowerShell

  • No dedicated cmdlet: You have to know the AccountExpirationDate (or raw accountExpires) filter syntax, which requires technical knowledge.
  • No built-in searching or management: The script produces a flat list; acting on the result requires you to run additional commands like Set-ADUser.
  • Manual exporting and scheduling: Getting the list into a specific format or running it on a cadence requires adding Export-Csv and configuring Task Scheduler.
  • Coarse access control: The cmdlets need directory read permissions, with no native mechanism to limit who can run the report or which accounts it covers.

How to find AD accounts that never expire using ADUC

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.

Prerequisites

  • Permissions: You need read access to the user objects, which a standard domain account has.
  • Tools: You need the ADUC console, which is part of RSAT on Windows 10 and 11 and is available by default on a domain controller.

Create a Saved Query with an LDAP filter

  1. Open ADUC by running dsa.msc.
  2. Right-click Saved Queries, select New > Query, and give the query a name such as Never-expiring accounts.
  3. Click Define Query, select Custom Search, open the Advanced tab, and enter this LDAP filter: (|(accountExpires=0)(accountExpires=9223372036854775807)).
  4. Click OK.

Limitations of ADUC

  • There’s no built-in never expires filter; you have to supply the raw LDAP filter manually and specify the correct accountExpires values.
  • Saved Queries have no dedicated report export workflow, so exporting the results requires additional steps or tools.
  • The query is local to that console; it isn’t shared, scheduled, or exportable to a file.

How to find AD accounts that never expire using ADManager Plus

ManageEngine ADManager Plus is a unified AD, Exchange, and Microsoft 365 management and reporting tool with a prebuilt report for non-expiring accounts.

Generate the Account Never Expires Users report

  1. Navigate to Reports > User Reports > Account Status Reports > Account Never Expires Users.
  2. Select the domain (or OU) and click Generate to list every account with no expiration date set.
  3. Click Export As to save the results in CSV, PDF, XLSX, or HTML format, or click Schedule Reports to generate and email the results on a recurring basis.
The Account Never Expires Users report generated in ADManager Plus.
The Account Never Expires Users report generated in ADManager Plus.

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.

Troubleshooting common errors

  • The report is empty or lists everyone: AccountExpirationDate was referenced without -Properties, so every account shows a blank value. Add -Properties AccountExpirationDate and run the filter again.
  • Get-ADUser is not recognized: The AD module isn't loaded. Run Import-Module ActiveDirectory; if that fails, install RSAT.
  • There's a filter syntax error: The -Filter string needs the value quoted correctly, as in "AccountExpirationDate -notlike '*'". A misquote or a misspelled attribute name causes the command to fail.
  • The LDAP filter returns nothing: Make sure it covers both never-expire values (0 and 9223372036854775807), since different accounts can use either.
  • The search is slow on a large domain: Scope it with -SearchBase to the relevant OU rather than searching the whole directory.

How ADManager Plus helps you find and manage stale accounts

ADManager Plus simplifies management and reporting across AD, Microsoft 365, and Exchange through a single console, reducing the need for scripts and individual queries.

Real-world use cases

Use case 1: Audit all non-expiring accounts for a security review

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

With ADManager Plus

  1. Navigate to Reports > User Reports > Account Status Reports > Account Never Expires Users.
  2. Generate the report, then click Export As to save it in the format the auditor needs.

Use case 2: Find stale, non-expiring accounts to clean up

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

With ADManager Plus

Use Automation to disable or remove the matching accounts from the Account Never Expires Users or Inactive Users report.

Configuring an automation in ADManager Plus to disable inactive users.
Configuring an automation in ADManager Plus to disable inactive users.

Use case 3: Review non-expiring service accounts

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

With ADManager Plus

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.

FAQ

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"

ADManager Plus Trusted By

The one-stop solution to Active Directory Management and Reporting