Find windows XP machines in Active Directory and Export

winserverMany windows admins these days are very busy upgrading/replacing windows XP. I am not going to go into how very important to remove windows XP machines from our environments since it is now EOL and no patches will be released any longer. What I am going to show you is how to find all those windows XP machines in your active directory. Because clicking on every computer object and finding the OS installed on it is for the birds. No one has that kind of time to waste!

what we need is to do is open active directory power shell this should be located in control panel / administrative tools / Active Directory Module for Windows Power Shell
The following queries will output all the windows xp machines names and the date of their last logon. by default it will make c:\work\computers.csv if you do not have a folder named work you will need to create that yourself as PS does not create folders for you and you may receive errors if you try to write the file directly tot he c drive.

the last logon will help you identify unused computer accounts in your environment that can be removed safely from AD.

from that prompt use the following line

PS C:\Windows\system32> Get-ADComputer¬† -Filter * -Properties OperatingSystem,LastLogonDate | where {$_.OperatingSystem -match “Windows XP Professional”} | select Name, OperatingSystem, LastLogonDate | sort LastLogonDate -unique | Export-Csv c:\work\computers.csv

or if you want to refine your search to a certain OU you can use the following query just edit the ou and dc information to suit your needs.

PS C:\Windows\system32> Get-ADComputer -SearchBase ‘ou=Computers,dc=yourdomain,dc=com’ -Filter * -Properties OperatingSystem,LastLogonDate | where {$_.OperatingSystem -match “Windows XP Professional”} | select Name, OperatingSystem, LastLogonDate | sort LastLogonDate -unique | Export-Csv c:\work\computers.csv