PowerShell Script: Search and Delete Active Directory Users who have been inactive for 180 days

## Search Users that have been inactive for 180 days.
Search-ADAccount -AccountInactive -TimeSpan 180 | Select-Object Name, LastLogonDate, DistinguishedName, SamAccountName | Export-Csv C:\Temp\NoExpiration2016.csv

## Delete Users from the above script
Import-CSV C:\Temp\NoExpiration2016.csv | ForEach-Object {Remove-ADUser -Identity $SamAccountName -Confirm:$False}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s