Tuesday, April 22, 2014

Get esx host for each vm using powercli

Here's a one liner to get the hostname of the vm is currently running on.

PowerCLI C:\cq> get-vm <VM-NAME> | select Name, @{N="Cluster";E={get-cluster -vm $_ }}, @{N="ESX Host";E={get-vmhost -VM $_}}

replace the VM-NAME with your VM.

for multiple VM, use comma (,)

eg:
get-vm vm01, vm02, vm03 | select Name, @{N="Cluster";E={get-cluster -vm $_ }}, @{N="ESX Host";E={get-vmhost -VM $_}}