Sunday, July 3, 2016

Find inactive AD user accounts -- Last Logon Date

This is a script I run weekly to ensure user objects are not being left in AD to get stale.  I have used this script for a few years and it reminds me to follow up on stale objects.  If you wanted to you could end this script with a send-mail command and add the exported CSV to as an attachment.

Start of script

# 8/30/2013
# Pulls a list of users that have not logged in for the last 90 days

Remove-Item 'C:\temp\90day_no_logon.csv' -recurse


Search-ADAccount -AccountInactive -UsersOnly -TimeSpan 90.00:00:00 | Select-Object Name, Description, Enabled, LastLogonDate, SamAccountName, DistinguishedName | Sort-Object Name | Export-Csv 'C:\temp\90Day_No_Logon.csv' -NoClobber -NoTypeInformation

End of script

No comments:

Post a Comment