Get All Virtual Machine Guest OS in Powershell

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

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.