PoshTip #27 – Get Inactive User Accounts in Active Directory

PoshTip #27 – Get Inactive User Accounts in Active Directory

Inactive Active Directory user accounts can pose a security risk to your organization. You can query Active Directory and generate reports about inactive user accounts.

First, import the AD module:

PS> Import-Module ActiveDirectory

Now you can use the “Search-ADAccount” cmdlet to query Active Directory:

PS> Search-ADAccount -UsersOnly -AccountInactive

You can add “-TimeSpan” parameter. The TimeSpan parameter specifies a time range from the “LastLogonDate” attribute to the current time:

PS> Search-ADAccount -UsersOnly -AccountInactive -TimeSpan 30.00:00:00 -searchBase "OU=Users,dc=DEMO,dc=local"

 

Note: 30.00:00:00 = 30 days

Thanks for reading! You can follow me on Twitter @PrigentNico

About Nicolas 282 Articles
I work as an IT Production Manager, based in Paris (France) with a primary focus on Microsoft technologies. I have 10 years experience in administering Windows Servers. . I am a Microsoft MVP for Cloud & Datacenter Management. I also received the PowerShell Hero 2016 award by PowerShell.0rg. And finally, I am "MCSE: Cloud Platform and Infrastructure", "MCSA: Windows Servers", "Administering & Deploying SCCM", and CheckPoint CCSA certified.