Just a quick script that lists all Windows VMs on a VMWare host and returns the version of Windows that is running. It goes without saying that you must have Administrative privileges on the machines being queried (this could be changed with a slight tweak to the Get-WMIObject command). Without further ado:
$output_file = “path_to_file”
$vms = Get-VM | ?{$_.PowerState -eq “PoweredOn”}
$vmos = foreach($vm in $vms) {Get-WmiObject -ComputerName $vm.Name Win32_OperatingSystem -EA SilentlyContinue | Select-Object @{Name=”ComputerName”; Expression={$vm.Name}}, @{Name=”OSVersion”; Expression={$a = $_.Name.split(“|”); $a[0]}}}
$vmos | Export-Csv $output_file -NoTypeInformation
write-host “Process complete. Output saved to $output_file” -foregroundcolor “yellow”