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 $ | 	where-object {$_.osfullname -ne $null} | select osfullname;
	write-host ($ + "," + $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 Comment

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