This article was originally posted on my personal blog IT Should Just Work back in 2014. In light of the recent WannaCry ransomeware outbreak, a script to find these old operating systems seems particularly relevant.
Some PowerShell/ PowerCLI to find all the VMs in an ESX environment which are powered on and running Windows XP or Server 2003.
In my VMware ESX environment I have (had) a number of virtual machines still running Windows XP or Server 2003- usually performing very specific tasks or allowing access to legacy applications, but still part of the production environment. With the (not so) recent End of Support for Windows XP and the upcoming one next year for Server 2003 I need to look at each of these VMs and see if they can be upgraded or decommissioned. Listing these in the GUI is fiddly at best- I want VMs with one of these two OSes, from any datacentre and I only care about VMs which are powered on. So, PowerCLI to the rescue:
get-vm |
where{$_.PowerState -eq"PoweredOn"-and($_.Guest -like"*Windows XP*"-or$_.Guest -like"*Server 2003*")}|
get-VMGuest |
select VmName, OSFullName
Sample Output:
VmName OSFullName
------ ----------
MyServer1 Microsoft Windows Server 2003 Standard (32-bit)
MyServer2 Microsoft Windows Server 2003 Standard (32-bit)
MyServer3 Microsoft Windows Server 2003 Standard (32-bit)
MyXPVM1 Microsoft Windows XP Professional (32-bit)
MyXPVM2 Microsoft Windows XP Professional (32-bit)
Not the most complicated piece of scripting, but it’s answered my question and I can refer back to it as upgrades continue to see what systems remain.