Monday, November 23, 2015

PowerCLI script to collect "Computers that have a specific OS installed"

I started looking for a way to inventory all of our VM's currently running within our 6-7 clusters. There was such a variety of OS's running that I didn't want to take the time to individually check the setting on each VM (500+ VM's). So after looking at different scripts, I took a combination of two or three and after trail and error I was able to filter my search results for exactly what I was looking for. In the end the script basically spits out the version of OS currently installed and IP Address of the VM. The IP address was critical in my search because we are running several different subnets and I needed to know exactly where the VM resided.

I then exported the results to my local C: drive in CSV format for viewing and reporting purposes.

# The *Cent* is changed to reflect what flavor of OS you may be looking for. *Red Hat*, *Server*, *Workstation*,etc..#
PS > get-vm | get-view | where {$_.Guest.GuestFullName -like "*Cent*"} | select Name,@{N="OS";E={@($_.Guest.GuestFullName)}},@{N="IP";E={@($_.Guest.IPAddress)}} | export-csv -path c:\tmp\vmware\CentOS.csv

No comments:

Post a Comment