June
15
Posted on 15-06-2012
Filed Under (powershell) by Dan

PowerCLI

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”

(1) Comment    Read More   

Comments

nexxphase on 10 July, 2012 at 5:57 am #

Thanks for the post. It has helped me a lot.


Post a Comment
Name:
Email:
Website:
Comments:
Prove you are human by reading this resistor:
0Ω+/- 5%

0
0
1
2
3
4
5
6
7
8
9

0
0
1
2
3
4
5
6
7
8
9

0
0
1
2
3
4
5
6
7
8
9

5
5
10
20

Match the sliders on the left to each color band on the resistor.

Click Here for a new resistor image.

If you'd like to learn more, read about resistor color codes here.