🎉 Our Microsoft 365 Reporting & Management Tool is now available in Azure Marketplace 🚀
This website uses cookies to improve your experience. We'll assume you're ok with this. Know more.
Active Directory

How to Find Expired User Accounts in Active Directory

Expired accounts in on-premises Active Directory often continue to exist even after users leave the organization. These accounts not only consume resources and client access licenses for services like Exchange Server and SharePoint Server but also pose security risks. Attackers can exploit them to gain unauthorized access, especially in hybrid environments. This guide explains how to list expired user accounts in Active Directory to maintain a secure environment.

Identify All Expired Users in Active Directory Using ADUC

Active Directory Permission Required
Account Operators Least Privilege
Administrators Most Privilege
  • To find all expired user accounts, you first need to determine the current UTC time in file time format, which will be used in the LDAP query. Run the following PowerShell command and note down the output value.
  • Windows PowerShell Windows PowerShell
     ((Get-Date).ToFileTimeUtc())
  • Next, open the Active Directory Users and Computers (ADUC) console. From the left pane, right-click Saved Queries and choose New → Query.
  • Enter a name and an optional description. Enable the checkbox Include subcontainers to ensure all users within nested OUs are included. Then, click Define Query.
  • Select Custom Search from the Find drop-down menu and switch to the Advanced tab.
  • Enter the following LDAP query after replacing <UTCTime> with the value obtained in previous PowerShell cmdlet execution.
    (&(objectCategory=person)(objectClass=user)(!(accountExpires=0))(!(accountExpires=9223372036854775807))(accountExpires<=<UTCTime>))
  • Click OK to save the query, then click OK again to close the configuration window.
  • Finally, select the newly created query under Saved Queries to list all expired user accounts in Active Directory
Identify All Expired Users in Active Directory Using ADUC

Find Expired User Accounts in Active Directory Using PowerShell

Active Directory Permission Required
Account Operators Least Privilege
Administrators Most Privilege
  • PowerShell provides a faster and more efficient way to find expired accounts than the ADUC console, which can be time-consuming.
  • If you are working on a non-domain controller machine, make sure the Active Directory PowerShell module is installed and imported.
  • Execute the following PowerShell cmdlet to get all expired user accounts in Active Directory.
  • Windows PowerShell Windows PowerShell
     Get-ADUser -Filter "AccountExpirationDate -lt '$((Get-Date).ToFileTimeUtc())'" -Properties Enabled, AccountExpirationDate | Format-Table Name, SamAccountName, @{Label='AccountStatus'; Expression={ if ($_.Enabled) { 'Enabled' } else { 'Disabled' } }}, DistinguishedName, AccountExpirationDate -AutoSize
  • This cmdlet retrieves all account expired users along with details such as name, SAM account name, account status, distinguished name, and account expired date.
Find Expired User Accounts in Active Directory Using PowerShell

Proactively Detect Account Expiration in Active Directory to Ensure Secure Access Management

AdminDroid’s Active Directory reporting tool offers deep insights into expired user accounts to help administrators identify accounts that are no longer valid and require timely action. It also enables better tracking of account expiration to maintain a secure and well-managed Active Directory environment.

Get a Quick Visual Overview of Account Expiry Details in Active Directory

Leverage the Active Directory users' dashboard to identify expired, never-expiring, soon-to-expire user accounts, etc., all at a glance, to improve domain security.

Track User Accounts Without Expiration Dates to Prevent Indefinite Access

Detect user account that never expire in Active Directory to prevent indefinite access and enforce security policies that align with compliance standards.

Identify User Accounts with Expiration Dates to Prevent Access Disruptions

Find users accounts with expiration dates to identify misconfigured account validity settings and correct them to prevent access disruptions.

Track Soon-to-Expire Accounts to Extend Access in Active Directory

Review accounts nearing expiration and extend access as needed to ensure continuous productivity for maintaining secure access control management.

Monitor Failed Login Attempts from Expired Accounts in Active Directory

Track failed login attempts from expired accounts to uncover unauthorized access attempts by attackers or accidental logon attempts by legitimate users.

Get Notified on Expiring Accounts in Active Directory

Automate account expiry reminders to notify admins and users about upcoming expirations for timely access management for temporary staff.

Overall, the AdminDroid Active Directory management tool streamlines updating user account properties such as enabled, disabled, expired, and more. It helps administrators maintain lifecycle management and ensure directory compliance.

Explore a full range of reporting options

Important tips

Ensure expired accounts are removed from all privileged group memberships to avoid potential access risks upon reactivation.

Verify that only critical accounts are set to “Never Expire” by conducting periodic reviews to prevent unauthorized long-term access.

Terminate all active sessions after an account expires to immediately block ongoing access, as account expiry does not end any existing sessions the user already has.

Common Errors and Resolution Steps

The following are possible errors that may occur while monitoring account expired users in Active Directory.

Error Search-ADAccount : Cannot validate argument on parameter 'SearchBase'. The argument is null. Provide a valid value for the argument and then try running the command again.

This error occurs when you try to run the cmdlet 'Search-ADAccount' with an incorrect OU name or a distinguished name of an OU that doesn’t exist in Active Directory.

Fix Verify whether the OU is present in your directory using the cmdlet below.
Get-ADOrganizationalUnit -Filter * | Select-Object Name, DistinguishedName

Error Set-ADAccountExpiration : Cannot bind parameter 'DateTime'. Cannot convert value "<DateTimeFormat>" to type "System.DateTime". Error: "String was not recognized as a valid DateTime.

This error occurs while executing the PowerShell cmdlet 'Set-ADAccountExpiration' using a date format that is either not supported or doesn't align with your system's regional settings.

Fix Make sure the date time format in the cmdlet matches your system’s regional settings, or use the universal format 'YYYY-MM-DD' or 'YYYY-MM-DD HH:MM:SS'.

Error Set-ADAccountExpiration : Insufficient access rights to perform the operation.

This error occurs when you execute the 'Set-ADAccountExpiration' cmdlet without proper access privileges.

Fix Ensure that you have the necessary Account Operators role or delegated OU permissions to set account expiration.

Error The query filter “<Query>” is not a valid query string.

This issue occurs when the applied LDAP filter is invalid while searching for expired accounts in Active Directory Users and Computers console.

Fix Confirm that the LDAP filter is correctly formatted and does not contain typing, syntax, or spacing errors after <UTCTime> is replaced as below.
(&(objectCategory=person)(objectClass=user)(!(accountExpires=0))(!(accountExpires=9223372036854775807))(accountExpires<=<UTCTime>))
Frequently Asked Questions

Effective Management of User Account Expiry Settings in Active Directory

1. How to check expired user accounts in a particular OU in Active Directory?

While finding expired accounts across the domain is essential, it is equally necessary to check specific OUs. Temporary staff, such as project-based staff or seasonal workers located in same OU, often have accounts with set expiration dates. If not reviewed, these accounts may expire unexpectedly and disrupt access. Regularly monitoring expired accounts in such OUs helps to ensure continuous access and a smooth transition for temporary users.

Find expired user accounts in a specific OU using ADUC

  • In Active Directory Users and Computers (ADUC), select the Saved Queries that shows all the expired accounts.
  • Right-click the query and choose Edit.
  • In the Edit Query window, click Browse next to Query Root, select the required OU, and click OK to save OU in query root.
  • Select OK again to save the query settings. Then, select the query and click Refresh ⟳ in tool bar to list all expired accounts from the chosen OU.
find-expired-users-in-ou-via-aduc

Identify expired AD user accounts in a specific OU using PowerShell

In ADUC, you must check each expired account individually to see the expiration date and enabled status. Meanwhile, PowerShell shows this for all accounts at once.

Run the following cmdlet after replacing <OUName> with OU name to get the expired accounts from that specific OU in Active Directory.

Search-ADAccount -UsersOnly -AccountExpired -SearchBase ((Get-ADOrganizationalUnit -Filter "Name -eq '<OUName>'").DistinguishedName) | Select-Object Name, SamAccountName, AccountExpirationDate, Enabled 

expired-users-in-ou-using-powershell

Gain insights of expired accounts in a specific OU in just a few clicks with AdminDroid!

  • With AdminDroid's Account Expired Users report, you can use the tree view to select the specific OU and instantly view all the expired accounts within it.
  • Additionally, the chart view displays expired accounts by status, department, job title, and more.
  • This feature allows for quick analysis and effective account management.
specific-ou-expired-users-via-droid

2. How to disable expired accounts in Active Directory?

Consider a situation where the security team finds that several user accounts in Active Directory have passed their expiry date but are still enabled. In a purely on-premises environment, this might not seem critical. However, in a hybrid setup, it becomes a security risk because the account expiry attribute is not synchronized to Microsoft Entra ID. This means that even though the account has expired in on-prem AD, the user can still sign in to Microsoft 365 and access cloud resources without interruption.

To prevent unauthorized access, it is important to disable expired accounts in Active Directory, rather than relying solely on expiration, especially in a hybrid environment.

Steps to disable expired user accounts using ADUC

  • Firstly, select the saved query you defined earlier in the Active Directory Users and Computers console to list all expired accounts.
  • Next, choose specific user account(s) or select all expired user accounts in the list.
  • Then, right click and choose Disable Account to disable the selected expired accounts in Active Directory.
disable-expired-users-in-aduc

Disable all expired Active Directory users using PowerShell

While the above method requires performing the steps manually through multiple navigations, PowerShell offers a more efficient way.

  • Make sure you have already installed and imported the Active Directory PowerShell module.
  • Execute the following PowerShell script to disable all expired users in both the Active Directory and Entra ID in hybrid environments.

$ExpiredEnabledAccounts = Search-ADAccount -AccountExpired | Where-Object { $_.Enabled -eq $true }   
if (-not $ExpiredEnabledAccounts) { 
    Write-Host "No enabled accounts found that are expired." -ForegroundColor Cyan 
    return 
} 
foreach ($User in $ExpiredEnabledAccounts) { 
    $Account = $User.SamAccountName   
    do { 
        $Confirm = Read-Host "Do you want to disable the account for '$Account'? (Y/N)" 
        if ($Confirm -notmatch '^[YyNn]$') { 
            Write-Host "Invalid input. Please enter 'Y' to disable or 'N' to skip." -ForegroundColor Yellow 
        } 
    } while ($Confirm -notmatch '^[YyNn]$') 
    if ($Confirm -match '^[Yy]$') { 
        Disable-ADAccount -Identity $User 
        Write-Host "Account '$Account' has been successfully disabled." -ForegroundColor Green 
    } 
    else { 
        Write-Host "Action skipped for account: $Account" -ForegroundColor Red 
    } 
} 

The script checks which expired accounts are still active. For each account, it asks for your confirmation to disable it, and after you respond, it immediately displays that account’s updated status.

disable-expire-accounts-using-powershell

3. How to extend the account expiry dates for all users in an OU in Active Directory?

Organizations often maintain accounts for temporary staff, contractors, or seasonal workers in a specific OU with predefined expiry dates. When their employment period extends, administrators need to update these expiry dates to prevent premature account expiry. Modifying expiry dates in bulk for all users in an OU ensures uninterrupted access for active users and streamlines account management tasks.

Change user account expiry dates in a specific OU using ADUC

  • In ADUC, navigate to the respective OU where you need to change the account expiration.
  • Select all the user accounts, then right-click and choose Properties.
  • Then, switch to Account tab, enable Account expires checkbox and select the End of: option.
  • Choose the desired expiry date, then click Apply and OK to save the changes.
change-account-expiry-using-aduc

Update the account expiry dates for users in a specific OU using PowerShell

Execute the following cmdlet after replacing <OUName> with the respective OU name and <YYYY-MM-DD> with the desired expiration date for all users in that OU.

Get-ADUser -Filter * -SearchBase (Get-ADOrganizationalUnit -Filter "Name -eq '<OUName>'" | Select-Object -ExpandProperty DistinguishedName) | Set-ADAccountExpiration -DateTime (Get-Date -Date "<YYYY-MM-DD>") 

Streamline the configuration of user account expiration dates across specific OUs using AdminDroid!

  • Without switching to a different view, you can modify account expiration dates directly from the same Account Expired Users report.
  • Select the OU, check the box next to the user’s display name.
  • Then, choose the Set Account Expiry to update the expiration date or set it to Never Expires and save your changes.
configure-account-expiration-via-droid

4. How to find who have changed account expiry dates in Active Directory?

When user account management is handled by multiple admins, expiry dates may be altered due to contract renewals or project extensions. Without proper tracking, this can lead to unauthorized access, non-compliance, lack of accountability, and security gaps in Active Directory. Therefore, admins need to monitor changes in account expiry to prevent operational disruptions.

Audit who modified the user account expiry dates using Event Viewer

Make sure to enable the Audit User Account Management policy in the GPMC and perform the steps below.

  • Open the Event viewer, then go to Windows Logs»Security.
  • In the right pane, click the Filter Current Log and enter the event id as 4738 in <All Event IDs> placeholder.
  • Click OK to display all user account change events with Event ID 4738. From the filtered results, choose the relevant event and review the Changed Attributes section to verify whether it includes an account expiry update.
  • If the event confirms an expiry modification, inspect the Subject Account Name field to identify the user who performed the account expiry change.

Note: You must review the Security logs on all domain controllers, as account modifications are recorded only on the domain controller that processed the change.

audit-log-who-changed-user-expiry-date
specific-event-log-of-changed-account-expiry-date

Detect users who changed account expiry dates in Active Directory using PowerShell

While the above method requires manually checking each event, PowerShell efficiently tracks who changed account expiry dates by querying security logs.

Run the following PowerShell cmdlet on a domain controller to view all events where the account expiry date was changed.

Get-WinEvent -FilterHashtable @{LogName = 'Security'; ID = 4738} |
Where-Object {
    $_.Message -match "Changed Attributes" -and
    $_.Message -match "Account Expires" -and
    $_.Message -notmatch "Account Expires:\s*-|Account Expires:\s*$"
} |
Select-Object `
    TimeCreated,
    @{Name = 'ChangedBy'; Expression = {
        ($_.Message -split "`n" | Where-Object { $_ -match "Account Name:" })[0] -replace '.*Account Name:\s*', ''
    }},
    @{Name = 'TargetAccount'; Expression = {
        ($_.Message -split "`n" | Where-Object { $_ -match "Account Name:" })[1] -replace '.*Account Name:\s*', ''
    }},
    @{Name = 'AccountExpires'; Expression = {
        ($_.Message -split "`n" | Where-Object { $_ -match "Account Expires" }) -replace '.*Account Expires:\s*', ''
    }},
    @{Name = 'Category'; Expression = { $_.TaskDisplayName }} |
Format-Table -Wrap -AutoSize

identify-who-changed-expired-dates-via-psscript

The output includes account expiration modifications that are recorded only on the domain controller where this command is executed. It displays details such as who made the change, the date and time of modification, targeted account, and the task category.

No more hopping between domain controllers to find out who changed accounts expiry dates!

  • With AdminDroid's Updated User Events report, you can easily find who have changed the account expiration dates by just applying Updated Attribute filter to Account-Expires.
  • This report includes key details such as the time of update, the user whose account was changed, who made the change, the new expiration date, and more.
  • Since AdminDroid can query all the selected domain controllers, you can track AD account expiry date changes without switching between domain controllers.
updated-user-with-account-expiry-via-droid

Kickstart Your Journey With
AdminDroid

Your Microsoft 365 Companion with Enormous Reporting Capabilities

Download Now
User Help Manuals Compliance Docs
x
Delivering Reports on Time
Want a desired Microsoft 365 reports every Monday morning? Ensure automated report distribution and timely delivery with AdminDroid's Scheduling to your email anytime you need.
Delivering Reports on Time
Schedule tailored reports to execute automatically at the time you set and deliver straight to the emails you choose. In addition, you can customize report columns and add inteligent filtering to the activities just from the previous day to suit your Microsoft 365 report requirements.
Set It, Schedule It, See Results- Your Reports, Your Way, On Your Time!
Time Saving
Automation
Customization
Intelligent Filtering
Give Just the Right Access to the Right People
Grant fine-tuned access to any Microsoft 365 user with AdminDroid’s Granular Delegation and meet your organization’s security and compliance requirements.
Give Just the Right Access to the Right People
Create custom roles loaded with just the right permissions and give access to admins or normal users within AdminDroid. The result? A streamlined Microsoft 365 management experience that aligns your organization's security protocols and saves your invaluable time and effort.
Align, Define, Simplify: AdminDroid's Granular Delegation
Smart Organizational Control
Effortless M365 Management
Simplified Access
Advanced Alerts at a Glance
Receive quick notifications for malicious Microsoft 365 activities. Engage with the AdminDroid’s real-time alert policies crafted to streamline your security investigations.
Advanced Alerts at a Glance
Stay informed of critical activities like suspicious emails and high-risk logins, bulk file sharing, etc. Through creating and validating ideal alert policies, AdminDroid provides a comprehensive approach to real-time monitoring and management of potential threats within your organization.
AdminDroid Keeps You Always Vigilant, Never Vulnerable!
Proactive Protection
Real-time Monitoring
Security Intelligence
Threat Detection
Merge the Required Data to One Place
Combine multiple required columns into one comprehensive report and prioritize the information that matters most to you with AdminDroid’s Advanced Column Customization.
Merge the Required Data to One Place
This column merging capability offers a flexible way to add different columns from various reports and collate all the essential data in one place. Want to revisit the customized report? Save it as a 'View’, and your unique report is ready whenever you need it.
Merge with Ease and Save as Views!
Custom Reporting
Unique View
Desired Columns
Easy Data Interpretation
Insightful Charts and Exclusive Dashboards
Get a quick and easy overview of your tenant's activity, identify potential problems, and take action to protect your data with AdminDroid’s Charts and Dashboards.
Insightful Charts and Exclusive Dashboards
With AdminDroid charts and dashboards, visualize your Microsoft 365 tenant in ways you've never thought possible. It's not just about viewing; it's about understanding, controlling, and transforming your Microsoft 365 environment.
Explore Your Microsoft 365 Tenant in a Whole New Way!
Executive overviews
Interactive insights
Decision-making
Data Visualization
Efficient Report Exporting for Microsoft 365
Downloading your reports in the right file format shouldn’t be a hassle with AdminDroid’s Report Export. Experience seamless report exporting in various formats that cater to your needs.
Efficient Report Exporting for Microsoft 365
Navigate through diverse options and export Microsoft 365 reports flawlessly in your desired file format. Tailor your reports precisely as you need them and save them directly to your computer.
Take Control, Customize and Deliver- Your Office 365 Data, Exported in Your Way!
Easy Export
Seamless Downloading
Data Control
Manage Microsoft 365

Get AdminDroid Office 365 Reporter Now!