With CentOS 7 reaching its end-of-life on June 30th of this year, it would be a good idea to identify any VMs with that particular OS. Doing so manually could prove tedious. Personally, I subscribe to the philosophy shared in Google’s SRE manual, and seek to eliminate such toilsome tasks. And PowerShell is a great tool for doing so!
First, import the module, and connect to your VIServer.
Import-Module -Name VMware.PowerCLI
Connect-VIServer -Server <servername|IP>
Then, run your query. Get-VM returns all VMs, then I pipe it to Select-Object to narrow down to just these objects’ Guest property, which contains OS information. Then, I pipe those results to Where-Object, where I can query for “*CentOS 7*”.
$VMs = Get-VM | Select-Object Guest | Where-Object {$_ -like "*CentOS 7*"}
Being able to quickly automate small tasks like this is an indispensable skill to a Systems Administrator. It makes you more efficient and more effective. Oh, and I almost forgot, be sure to Disconnect-VIServer when you are done!
Disconnect-VIServer