Removing invalid VMs in VMWare ESXi

Table Of Contents

Hi there.

Today will be a short one.

Recently we replaced our old VMWare cluster with 3 new ProLiant DL325 Gen10 Plus v2 Servers and a MSA2062. This meant that we had old Hardware lying around for testing purposes.

After migrating the VMs and moving the hardware to another rack, we somehow lost the connection to one of the old storage systems. How it happened, I don’t really know. We must have plugged it wrong somehow, but since we do not actually need it anymore, it didn’t really matter.

Anyway, the issue now is that we have a lot of invalid VMs showing up in the WebUI.

To get to the point, I want to show you have to remove those, since it’s not actually possible (at least I didn’t find a way) to do this through the WebUI.

Removing invalid VMs

First connect to the ESX Host via SSH.

fedora-kde :: ~ » ssh root@ 
(root@ Password: 

Next we can list the VMs and their ID. Once we have the ID we want to remove, we can unregister it with the same command.

[root@localhost:~] vim-cmd /vmsvc/getallvms
159    Wazuh                            [SAS_Diskpool] Wazuh/Wazuh.vmx                                                     centos7_64Guest         vmx-13          
161    Debian                           [SAS_Diskpool] Debian/Debian.vmx                                                   debian10_64Guest        vmx-13          
162    TEST-DC01                        [SAS_Diskpool] TEST-DC01/TEST-DC01.vmx                                             windows9Server64Guest   vmx-13
[root@localhost:~] vim-cmd /vmsvc/unregister 159

If you have multiple invalid VMs you want to remove, you could use a while script, as long as the IDs are in a range.

[root@localhost:~] x=(First ID to remove)
[root@localhost:~] y=(Last ID to remove)
[root@localhost:~] while [ "$x" -le "$y" ]; do vim-cmd /vmsvc/unregister $x; $(( x++ )); done

-le (smaller or equal to)

This will loop through the IDs until it reaches the last ID defined in “y”. There might be a better way to do this, but it worked for me.

That’s it. Till next time.

Leave a Reply