Counts of VM's running specific OS types

This was a fun little exercise for me in getting a count of VM's per OS type spawned off by a question in the vmware communities board.  The result would look something like this:

It's quite simple and probably could be written a bit more efficiently, but ran sufficiently fast enough for me.
$TotalVMs = Get-View -ViewType VirtualMachine -Property Name,'Summary.Config.GuestFullName'
$OSFilters = $TotalVMs | select -ExpandProperty summary | select -expandproperty config | select -unique guestfullname | sort


$MyCustomReport = New-Object PSObject
Foreach ($OSFilter in $OSFilters)
     {$MyCustomReport | Add-Member -Name $OSFilter.GuestFullName -MemberType NoteProperty -Value ($totalvms | select -expandproperty summary | select -expandproperty config | where {$_.GuestFullName -eq $OSFilter.guestfullname}).count}
$MyCustomReport | Add-member -Name Total -MemberType NoteProperty -Value $TotalVMs.Count


$MyCustomReport

Comments

Popular posts from this blog

NSX-T: vCenter and NSX-T Inventory out of Sync (Hosts in vSphere not showing up in NSX-T)

MacOS: AnyConnect VPN client was unable to successfully verify the IP forwarding table modifications.

vCenter: Cluster Skip Quickstart Workflow via API