Pinging all VMs on an ESXi Host (or other vCenter Container)

Here's a quickie.  As part of this big vCenter forklift, we want to verify that all VMs are communicating on the network after they've been migrated to the destination systems.  I shudder to imagine someone typing out "ping vma" and then "ping vmb" etc. for all of these machines... and so I created this command to do the work for us!  It grabs the list of all VMs from the host esx01, then does two tests.  First, it checks to see if the vm has a hostname (from VMware tools), then it attempts to ping that hostname.  If the VM doesn't have a hostname or if that VM doesn't respond to ping, the command spits out a quick message saying that the VM failed to ping.

get-vmhost *esx01* | get-vm | foreach {if(!($_.guest.hostname) -or !(Test-Connection $_.guest.hostname -count 1 -quiet)){echo "$($_.name) failed to ping"}}

Quick note - this command uses the test-connection cmdlet, which was introduced in PowerShell 4.0.  You can use $psversiontable.psversion to discover what version of PowerShell you're running.  If it's too old (all you people still on Windows 7, I'm looking at you), make sure that you install dotNet 4.5 and then the latest Windows Management Framework, to save yourself some headache.

Comments

Popular posts from this blog

Clone a Standard vSwitch from one ESXi Host to Another

PowerShell Sorting by Multiple Columns

Deleting Orphaned (AKA Zombie) VMDK Files