Get All Virtual Machine Guest OS in Powershell

This article was posted more than 1 year ago. Please keep in mind that the information on this page may be outdated, insecure, or just plain wrong today.

Continuing with learning some Powershell, I cooked this up which will connect to the vCenter server and get all the VM’s and list the name, operating system and power state.

foreach ($vm in get-vm) {
	$os=get-vmguest -vm $vm.name | 	where-object {$_.osfullname -ne $null} | select osfullname;
	write-host ($vm.name.tostring() + "," + $os.osfullname + "," + $vm.powerstate.tostring()) -ErrorAction silentlycontinue
}

Example Output

VM01,Microsoft Windows Server 2008 R2 (64-bit),PoweredOn
VM02,Microsoft Windows Server 2003 (32-bit),PoweredOn
VM03,Microsoft Windows Server 2008 R2 (64-bit),PoweredOn
VM04,Microsoft Windows Server 2003 (32-bit),PoweredOn

#powershell