Invalid State of a Virtual Machine on VMWare ESXi
Quite often, VMWare administrators are faced with the fact that the list of virtual machines contains VMs with the Invalid (Unknown) status. As a rule, the issue occurs after deleting a virtual machine, which data remained in the VMWare vSphere/ESXi configuration on some reason. This can also happen after you manually remove VM files from the VMFS storage after running vMotion and in some other cases. You won’t be able to delete such a VM from vSphere Web Client using the built-in tools (the Unregister option in the Actions menu is inactive).
vmware esxi invalid (unknown) state of vm in console
The only way to remove such a VM is to use the SSH console of the ESXi host.
Enable SSH on the ESXi host with the problem VM (Actions -> Settings -> Security Profile -> Services -> SSH -> Edit -> Start); enable ssh on esxi
Connect to the ESXi host using SSH client (Putty, mputty, etc.);
To get the ID of the problem virtual machine, run this command: vim-cmd vmsvc/getallvms | grep invalid
A list of all VMs with the Invalid status registered on this host will be displayed. There should be a string like: Skipping invalid VM ’22’. In this case, 22 is the ID of the virtual machine;
If you want to try and restore this VM in vSphere, run the command: vim-cmd vmsvc/reload 22 (in a minute refresh the client interface and check the VM status);
If you want to unregister (delete) a problem virtual machine, run the following command: vim-cmd /vmsvc/unregister 22
Refresh the vSphere client interface. The virtual machine with the Invalid status should disappear.
Also you can manually delete the problem VM from the host configuration file /etc/vmware/hostd/vmInventory.xml. To do it, delete the section containing the data of the problem VM from the vmInventory.xml file (backup the file before doing anything) in a text editor (vi, nano) and restart the host services: services.sh restart
vmInventory.xml file – vm config entry
If a running virtual machine gets the Invalid status, it is likely that the VM configuration file is corrupted. To resolve the issue:
Remove the VM from the inventory and restart the ESXi host;
Then create a new VM and connect the virtual disks (vmdk) of the old VM to it (Use an existing disk);
Perform Storage vMotion to collect all files of the new VM in a single folder;
Start your new VM and make sure that it works;
Delete the files of the old VM.
If the problem of the Invalid VM appeared after losing access to VMFS storages, when the access is restored the started VMs will run and the stopped ones will become isolated. You will have to manually remove them from the inventory and manually register them by finding the VMX file of a virtual machine in the VMFS storage, right-clicking it and selecting Register VM. Then start the VM and make sure that it is available.