Reload invalid VM’s with this PowerCLI with ESXI 6.5

Sometimes you might have an issue with storage or Veeam backup with Veeamproxy locking files and preventing VM consolidation from occurring. I had an issue where one of my VeeamProxy VM servers became an invalid state and I wasn’t able to power the server up. Since it crashed it locked the files of VM’s that were being backed up and I wasn’t able to consolidate the VM. One way was to use PowerCLI with command:

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

Essentially the reload function through PowerCLI forces the VM Inventory Management to reload the VM without the need to do a manual process of unregistering and re-registering the VM. The VM was reloaded but I still had to reboot my esxi host since I wasn’t able to unregister and re-register it as I wasn’t able to delete the VM from the inventory.