I was given a hard copy list of 80 plus computers on our network that were still running XP and was asked to type it out on a spreadsheet.  Naturally, my IT instincts kicked in.  You know, the What-Is-The-Laziest-Possible-Way-To-Accomplish-This-Task instincts, er, I mean what is the most time efficient way to handle this task.  I certainly did not want to spend all day manually typing out convoluted information like YXZ-51ONS1256A 80 times to have a digital copy of this list.  Once again my very supportive friend, Powershell, comes to my rescue!

Long story short, after a bit of trial and error (our AD is not very clean: with computers that were never decommissioned or deleted properly) I accomplished the task in a fraction of the time it would have taken if I were to manually enter the information.

So, since our AD had computers that were technically not on our network but would still show up on a list if I just used “Get-ADComputer”, I decided to use a filter with the “LastLogonTimeStamp” with a “greater than” date variable.

This will be used for the base date stamp.  Variable recalls today’s date minus 60 days.  I figured to pull up computers with a time stamp of “at least” 60 day ago would bring up the most current computer utilized on our network.

$d = [DateTime]::Today.AddDays(-60)

The filter used to list the computers is “list all computers if LastLogon is greater than (-gt) today’s date minus 60 days”.  I could have also added an operating system -eq XP to the filter as well but I figured I can clean that information up in the CSV file later.  Also, the full list can be utilized as a full inventory as well.  The “|” will pipe the information it pulls to the next line of code.

SIDE NOTE: Here is some further information I found helpful about Filter operators.  Found it here
FilterOperators

Get-ADComputer -Filter {LastLogonTimeStamp -gt $d} -Properties * |

Since Get-ADComputer will list all information about the computers if finds, you might want to exclude information you do not need.  That is were Select-Object comes in.  All the “objects” listed is the only information I needed in this case and that information will be sent to the Export-CSV command which will create a CSV file.

select-object Name,ipv4Address,OperatingSystem,OperatingSystemServicePack,OperatingSystemVersion | export-csv c:\Computers.csv

After the CSV was created, I opened it and filtered by columns and deleted all the computers that were not listed as XP Operating Systems and that’s it!