Powershell script to find and filter computers by Operating System and active/logondate

Copy and past the below script into a notepad or PowerShell ISE

Change the “name” filelds after -searchbase to correspond to your domain OU which you want to run the query for

Open c:\Windows2008.csv in Excel, sort by Date Column and remove older entries you don’t want

Import-Module ActiveDirectory

get-adcomputer -searchbase ‘ou=name,ou=name,ou=name,dc=name,dc=name’ -Filter {OperatingSystem -like “*2008*”} -Properties * | select name, OperatingSystem, LastLogonDate > c:\Windows2008.csv

Use PowerShell script below if you prefer a grid view instead of a csv file

Import-Module ActiveDirectory
get-adcomputer -searchbase ‘ou=servers,ou=computers,ou=epi,dc=apd,dc=dev’ -Filter {OperatingSystem -like “*2008*”} -Properties * | select name, OperatingSystem, LastLogonDate | out-gridview

Advertisements