List VM’s and host details

By | May 3, 2019

Today there were some issues with the storage system of our management environment at our secondary site and we had to do some onsite troubleshooting. As a precaution we turned off the running VM’s, before doing this we wanted to know where the VM’s resides on which ESXi node with some extra info that could be useful in a troubleshooting scenario.

To achieve this I used the following PowerCLI script:

Get-VM |
Select Name,PowerState,
    @{N='VMHost';E={$_.VMHost.Name}},
    @{N='IP';E={$_.Guest.IPAddress -join '|'}}

This will give you an overview of the “running” VM’s on the corresponding ESXi node and could be useful if you want to locate your vCenter VM for instance.

To shutdown all VM’s in an automated fashion I used the following script:

Get-Cluster OMS-Alm | Get-VM | Shutdown-VMGuest -Confirm:$false -RunAync:$true

If you want to exclude the vCenter from shutting down then use:

Get-Cluster OMS-Alm | Get-VM | ?{$_.Name -ne "vCenterName"} | 
Shutdown-VMGuest -Confirm:$false -RunAync:$true

To view the results in a separate window add “Out-Gridview” to the script.

*Courtesy of LucD en R.Kleijwegt.

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.