PowerShell – Return Inactive Computer Accounts

email me


# Return Inactive Computer Accounts from AD

# Days Inactive
$Days=180

# File for output
$OUTPUT='C:\_PowerShell\output.csv'

# Today's date for comparison
$TODAY=GET-DATE

# Quest Tools http://eddiejackson.net/apps/Quest_ActiveRolesManagementShellforActiveDirectoryx64_151.zip
GET-QADCOMPUTER -SizeLimit 0 -IncludedProperties LastLogonTimeStamp |
where { ($TODAY-$_.LastLogonTimeStamp).Days -gt $Days } |
Select-Object Name, LastLogonTimeStamp, OSName, ParentContainerDN |
Sort-Object ModificationDate, Name |
Export-CSV $OUTPUT