🎉 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 Soon to Expire User Accounts in Active Directory

Unnoticed account expirations in Active Directory often cause sudden access issues and force IT teams to act quickly. Without proactive monitoring of upcoming account expirations, users may either lose access unexpectedly or retain access longer than intended. This guide explains how to identify and manage soon-to-expire accounts in Active Directory to avoid access disruptions and ensure timely admin action.

Get Expiring User Accounts in Active Directory using ADUC

Active Directory Permission Required
Domain Users Least Privilege
Administrators Most Privilege
  • To find soon to expire AD accounts using ADUC, you need an LDAP query with the ‘accountExpires’ attribute in Windows FileTime format.
  • Since calculating this value manually isn’t straightforward, you can generate the required LDAP query using PowerShell based on your preferred expiration threshold.
  • Run the PowerShell cmdlet below to generate an LDAP query to find user accounts that will expire in the next 7 days.
  • Windows PowerShell Windows PowerShell
     $ExpiringDays= 7 
    $today = Get-Date 
    $future = $today.AddDays($ExpiringDays)  
    $todayFileTime = $today.ToFileTime()  
    $futureFileTime = $future.ToFileTime() 
    Write-Output "(&(objectCategory=person)(objectClass=user)(accountExpires>=$todayFileTime)(accountExpires<=$futureFileTime))" 
    ldap-find-expiring-accounts
  • Note: You can replace the value of ‘$ ExpiringDays’ to customize the expiration window.
  • Then, open the Active Directory Users and Computers (ADUC) snap-in, click on the Action menu, and select ‘Find’.
  • In the Find field, select Custom Search and navigate to the Advanced tab. Choose your desired domain using the Browse option.
  • Now, paste the generated LDAP query and click Find Now to view the AD user accounts expiring in the next 7 days.
Get Expiring User Accounts in Active Directory  using ADUC

List All Soon to Expire AD Accounts Using PowerShell

Active Directory Permission Required
Domain Users Least Privilege
Administrators Most Privilege
  • Ensure the Active Directory PowerShell module is installed on your machine. If installed, run the cmdlet below to import it.
  • Windows PowerShell Windows PowerShell
     Import-Module -Name ActiveDirectory
  • Run the PowerShell script below to find AD users expiring in 7 days. The script converts accountExpires to date format for user convenience.
  • Windows PowerShell Windows PowerShell
     $ExpiringDays = 7 
    $time = (Get-Date).AddDays($ExpiringDays)
    $today = Get-Date 
    Get-ADUser -Filter {accountExpires -lt $time -and accountExpires -gt $today} -Properties * |Select-Object Name, @{Name="ExpiryDate"; 
    Expression={[datetime]::FromFileTime($_.accountExpires)}}, WhenCreated, Manager| 
    Format-Table -AutoSize 
    accounts-expiring-in-7-days-powershell
  • Note: You can replace the value of ‘$ExpiringDays’ with a different threshold based on your requirements.
  • Alternatively, for a simpler approach, use the “Search-ADAccount” cmdlet below and adjust -TimeSpan parameter value to suit your requirement.
  • Windows PowerShell Windows PowerShell
     Search-ADAccount -AccountExpiring -TimeSpan "7" | 
    Where-Object { $_.ObjectClass -eq "user" }| 
    Select-Object Name, Enabled, AccountExpirationDate| 
    Format-Table
    search-soon-to-expire-accounts-powershell

Prevent Last-minute Access Issues by Monitoring Soon-to-expire AD Accounts!

AdminDroid’s Active Directory reporting tool helps maintain business continuity by identifying user accounts nearing expiration. With its advanced capabilities, you can receive alerts about upcoming expirations, extend access when needed, and more.

Detect Logons from Expired Active Directory Accounts

Review login attempts by expired Active Directory users to identify unauthorized access or determine if they need extended access.

Identify Active Directory User Accounts that Never Expires

Check AD accounts without expiration and set an appropriate expiration date directly from the portal to ensure temporary users don’t retain indefinite access.

Monitor Soon to Expire AD Accounts from a Centralized Dashboard

Avoid sudden access disruptions by identifying users whose AD accounts are set to expire in the next 7, 30, or 60 days from the centralized user dashboard.

Audit Disabled Tasks to Avoid Missed Expiration Notifications

Create alerts for any disabled scheduled tasks events to ensure account expiration notification scripts continue running without any interruption.

Find Users Without Managers to Streamline Expiration Workflows

Spot Active Directory users without a manager and update their records to prevent delays in account deactivation or extension approvals when the account expires.

Notify Managers About User Account Extensions

Trigger workflows to extend the account expiry date of users and notify their managers to make sure they’re aware of the continued access.

Overall, AdminDroid ensures you're always ahead of user account expirations in Active Directory by delivering timely alerts, extending access when needed, and enabling quick deactivation of expired accounts.

Explore a full range of reporting options

Important Tips

Set shorter expiration periods for external users and extend them only when needed to reduce unnecessary long-term access.

Disable expired accounts in Active Directory instead of deleting them to preserve user data and allow easy reactivation if needed.

Keep an eye on how often accounts are extended to identify misuse and prevent temporary accounts from turning into long-term security risks.

Common Errors and Resolution Steps

The following are possible errors and troubleshooting hints while dealing with expiring accounts in Active Directory.

Error The user account has expired. For assistance, contact your system administrator or technical support.

This error occurs when users trying to login from an expired account.

Fix If they’re a valid user, run the cmdlet below to extend their account expiration date.
Set-ADAccountExpiration -Identity "<SamAccountName>"  -DateTime "<MM/DD/YYYY>" 

Error Set-ADAccountExpiration : Cannot bind parameter 'DateTime'. Cannot convert value "18/10/2025" to type "System.DateTime". Error: "String was not recognized as a valid DateTime."

This error occurs when the date value is passed in an incorrect format that doesn’t align with your system’s locale settings.

Fix Mention the date value according to your system’ s locale settings. Otherwise, update your system’s regional settings to match the date format you're using.

Error Exception calling "FromFileTime" with "1" argument(s): "Not a valid Win32 FileTime."

This error occurs when you try to get and convert the ‘accountExpires’ value to date format of an Active Directory user whose account is set to ‘Never Expire’.

Fix Instead of manually converting 'accountExpires', use the 'AccountExpirationDate' property. For accounts set to 'Never Expire', it will simply show as $null.
Get-ADUser -Filter {SamAccountName -eq "<SamAccountName>"} -Properties AccountExpirationDate| 
Select-Object Name, AccountExpirationDate    

Error The term 'Set-ADAccountExpiration' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

This error occurs when the Active Directory PowerShell module is not installed or loaded on your machine.

Fix If you’re running the cmdlet directly from your DC, use the command below to import it, since the AD module is installed by default.
Import-Module -Name ActiveDirectory
// If you’re running the cmdlet from a member server or a workstation, run the cmdlet below to install the AD module and then import it. 
Install-WindowsFeature RSAT-AD-PowerShell
Frequently Asked Questions

Minimize Downtime with Real-time Visibility into Upcoming Account Expirations

1. How to find expiring user accounts in an Active Directory OU?

Not every expiring account in Active Directory needs attention, especially when you manage only users in a specific location. In this scenario, you can filter by Organizational Unit (OU) to ensure you stay informed about expiring accounts within your scope. This targeted approach helps streamline user management, offboarding, and security compliance while avoiding unnecessary queries.

Get soon-to-expire users in Active Directory from specific OU using ADUC

  • Open the Active Directory Users and Computers (ADUC) console.
  • Right click on the desired OU from the left pane and select Find.
  • In the Find field, select Custom Search and navigate to the Advanced tab.
  • Now, paste the previously generated LDAP query from PowerShell, and click Find Now.
expiring-users-in-an-OU

This will list all AD user accounts set to expire in the selected OU and its nested OUs based on the specified criteria in the LDAP query.

View expiring AD user accounts in a specific OU using PowerShell

While the above ADUC console approach displays expiring user accounts in both the OU and its sub-OUs, the SearchScope parameter in PowerShell lets you filter results to just the parent OU.

$ExpiringDays = "<DesiredDays>"    
$time = (Get-Date).AddDays($ExpiringDays)  
$today = Get-Date 
Get-ADUser -SearchBase "<OUDistinguishedName>" -SearchScope OneLevel  -Filter {accountExpires -lt $time -and accountExpires -gt $today} -Properties * |
Select-Object Name, @{Name="ExpiryDate"; 
Expression={[datetime]::FromFileTime($_.accountExpires)} },WhenCreated, Manager |  
Format-Table –AutoSize 
accounts-expiring-in-ou-powershell

If you're unsure about the OU’s distinguished name, use the cmdlet below to retrieve it.

Get-ADOrganizationalUnit -Filter "Name -eq '<OUName>'" | 
Select-Object DistinguishedName 

2. How to set account expiration date for users in a specific group in Active Directory?

To ensure user accounts expire at a specific time, you can set expiration date in Active Directory using the ADUC console for a single user, or PowerShell for multiple users.

But what if you want to set expiration dates for users in a specific Active Directory group?

This is especially helpful when managing contractors or interns who have been added to a dedicated security group for resource access. In such cases, you can run the PowerShell script below to assign a common expiration date to all users within that group.

$DaysToExpire = 10 
$ExpiryDate = (Get-Date).AddDays($DaysToExpire) 
Get-ADGroupMember -Identity "<GroupName>" -Recursive | 
Where-Object { $_.ObjectClass -eq 'user'} | 
ForEach-Object { 
Set-ADUser -Identity $_ -AccountExpirationDate $ExpiryDate } 

You can run the ‘Get-ADGroup’ cmdlet to fetch the group name and then replace it with the ‘GroupName’ value in the above script.

Quickly filter users based on a specific group and set expiration dates for them in just a few clicks with AdminDroid!

  • Navigate to the Active Directory Group and Member Details report and filter users based on their group using the Group Name filter.
  • Select all the users, then click "More Actions" and choose "Set Account Expiry" to set the expiration date.
set-expiration-date-multiple-users

3. How to notify admins when Active Directory users accounts are about to expire?

Unexpected user account expirations can disrupt work and burden IT teams with last-minute access requests. To avoid such situations, you can use PowerShell to send Active Directory account expiration email notification to specified admins. This proactive approach enables admins to either extend the account’s validity or allow it to expire and disable it accordingly.

Use the PowerShell script below to notify admins 10 days before user accounts expire by sending a predefined email notification.

You can replace the value of ‘$ExpiringDays’ with a different threshold based on your requirements.

$ExpiringDays = 10  
$Today = Get-Date  
$ExpirationDate = $Today.AddDays($ExpiringDays)  
$Credential= Get-Credential 

$ExpiringUsers = Get-ADUser -Filter 
 { 
   accountExpires -lt $ExpirationDate -and accountExpires -gt $Today -and Enabled -eq $true 
 } -Properties accountExpires, Enabled, Name 
foreach ($user in $ExpiringUsers) 
 {  
  $FormattedExpiryDate =[datetime]::FromFileTime($user.accountExpires).ToShortDateString()  
  $UserName= $user.Name 
  $subject = "Upcoming account expiration alert for $UserName"  
  $body =  @" 
    Hello Admin,<br> 
    This is a reminder that the Active Directory account of $UserName is scheduled to expire on $FormattedExpiryDate. 
    <br> 
    Please take the necessary action if this account needs to be extended or deactivated. 
    <br> 
    Thank you."@ 
  Send-MailMessage -To "<AdminEmailAddress>" -From "<NotificationEmailAddress>" -Subject $subject  -Body $body –BodyAsHtml -SmtpServer "<SMTPAddress>" -Port 587 -UseSsl -Credential $Credential
} 

Note: The ‘Send-MailMessage’ is considered obsolete as it doesn't support modern authentication or robust security standards. As a secure and up-to-date alternative, you can use the MailKit library , which offers better support for encryption, authentication, and modern protocols.

You can use Task Scheduler to run the script based on your desired frequency. However, it introduces challenges like script failures and credential issues, which may result in missed notifications and delays in operations.

Get Real Time Alerts for Expiring AD User Accounts to Prevent Unexpected Lockouts!

With AdminDroid, you can easily create alerts for expiring Active Directory users and send notifications directly to the desired recipients without configuring SMTP.

alert-on-expiring-users

You can use ‘Alerts Overview Dashboard’ in the AdminDroid portal to visualize and analyze all the account expiration alerts in Active Directory.

4. Can expired accounts be extended in Active Directory?

Once a user account expires in Active Directory, they can no longer log in. If the expiration is intentional, you can disable the account to minimize security risks. However, there are scenarios where extending the expiration date of the account may be necessary.

  • Onboarding a Former Contractor: Instead of creating a new account for a former contractor joining another project, you can simply extend their expiration date to restore access and preserve previous configurations.
  • Unintentional Account Expiration: If user accounts expire unintentionally due to missed renewals, you can extend their expiration date to avoid access disruptions.

Once you've identified the expired users who need extended access, you can set a new expiration date using the Set-ADAccountExpiration PowerShell cmdlet. This will extend their access based on the value you specify.

Set-ADAccountExpiration –Identity  "<SamAccountName>" -DateTime "<ExpirationDate>" 

If an important admin’s account is expired unintentionally, you can just use the Clear-ADAccountExpiration cmdlet to set their expiration date to ‘Never Expires’.

Clear-ADAccountExpiration –Identity "<SamAccountName>" 

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!