Around the Storage Block
Showing results for 
Search instead for 
Did you mean: 

Reload inaccessible or invalid VMs


Have you ever had a blip in your network, or a temporary network outage?  Has your VMware vSphere environment recovered completely after that?  Or did you end up in an annoying situation where your network/FC storage (iSCSI, FCoE, NFS, FC) took a little "longer" to come up, as compared to your ESXi servers?  In such cases, you may end up with a situation where the VMs in your vSphere environment show up as "inaccessible".  One way to remedy the situation is to unregister each VM and re-register the VM's vmx file to vCenter or the ESXi host.  But if you have an environment larger than 10 VMs, this can become a tedious, manual task.  Within our QA environments, we often end up breaking things and need a fast, automated way to recover.

Inaccessible VMsInaccessible VMs

Command-line scripts with vim-cmd

VMware KB 1026043 outlines this solution: reload the VM's vmx file on the ESXi host using the vim-cmd commands: 

  1. Get the VM's Vmid with this command, to identify your VM:      #vim-cmd vmsvc/getallvms
  2. Reload the VMX using the reload command:      #vim-cmd vmsvc/reload Vmid

A one-liner script combining the two steps above, to be run on each ESXi server in your environment, as root:

for a in $(vim-cmd vmsvc/getallvms 2>&1 | grep invalid | awk '{print $4}' | cut -d \' -f2); do vim-cmd vmsvc/reload $a; done

In large environments, this can be a tedious job.  Within a QA environment with 8 servers too, we wanted this automated.  An option was indeed to configure password-less root ssh into each ESXi server, and run the script from a central desktop.  But we wanted something more secure, less error-prone and with fewer breaking points.

PowerCLI to the rescue

A little more searching fetched us a PowerCLI one-liner solution!  Logging in as administrator in your vCenter, you can execute this and it runs on ALL VMs in your inventory, on ALL ESXi servers.

(Get-View -ViewType VirtualMachine) | ?{$_.Runtime.ConnectionState -eq "invalid" -or $_.Runtime.ConnectionState -eq "inaccessible"} | %{$_.reload()}

Source: from techazine or

Let's break it down to understand the parts of this one-liner:

  • Get-View -ViewType VirtualMachine
    Retrieves all VMs in your vCenter inventory.  The next part:
  •  ?{$_.Runtime.ConnectionState -eq "invalid" -or $_.Runtime.ConnectionState -eq "inaccessible"}
    This filters the VMs and looks for invalid or inaccessible VMs only.  The last part:
  • %{$_.reload()}
    This calls the vSphere reload API.

Voila!  Just like that, your VMs are all back online and accessible!

HPE Nimble Storage
About the Author


VMware and Nimble Storage QA engineer