Friday, August 16, 2013

Get inactive computer account from Active Directory

Using this Script will give you a list of all inactive computer account using "lastlogondate" attribute.

The result will be stored in C:\ActiveComputers.csv


Import-Module ActiveDirectory

# get today's date
$today = Get-Date

#Get today - 60 days (2 month old)
$cutoffdate = $today.AddDays(-60)

#Get the computer accounts filtered by lastlogondate. Select
#only required properites of the computer account and
#export it to a file
Get-ADComputer  -Properties * -Filter {LastLogonDate -gt $cutoffdate} | `
Select Name,OperatingSystem,OperatingSystemVersion,LastLogonDate,CanonicalName | `
Export-Csv C:\ActiveComputers.csv

No comments: