Friday, February 17, 2017

Deleting an orphaned virtual machine when the Remove option is not available

So, I was testing out our new lab environment this week for the VMware Authorized class; vSphere Install, Configure & Manage 6.5, when I realized the current version has the student inadvertently create an orphaned VM.

The interesting thing is how it happened and what the resolution is.

So, we have a VCSA 6.5 vCenter and 2 ESXi 6.5 hosts joined to it.  The lab manual has us build a nested VCSA VM to run through the installation of VCSA.  AS soon as you get the VM setup, they have you delete it.  BUT, they have you use the new embedded Host Client which debuted in ESXi 6.0 with Update 2. 

Since you do this from the host & NOT from the Web Client or new vSphere Client (HTML5) through vCenter, the VM is gone, but the object in vCenter inventory that represents the VM still exists and shows up as orphaned:
 
No problem you say, just right click on it and choose Remove or choose Remove from the Actions menu... not so fast, it doesn't exist there:
 
Ok you say, well, surely it must be available in the new vSphere Client (HTML5), right?  NOPE:
 
OK, so how do you remove it from inventory when there are no options to do so.  Well, thanks to KB 1011468 https://kb.vmware.com/kb/1011468, we have a workaround. 
Here are the steps:
  1. Open VMware Infrastructure or vSphere Client and connect to vCenter Server with a user with Administrative rights.
  2. Change the view to the VMs and Templates inventory view.
  3. On the left pane, right-click vCenter Server, click New Folder and provide an alpha-numeric name to the folder.
  4. Click the virtual machine and while holding the left mouse button, drag the virtual machine to the folder created in step 3.
  5. Right-click the folder, and click Remove. The folder and its contents are deleted.
Simple right?  Wrong...
This KB is OLD, so in Step 1 in vSphere 6.5, you might see a problem ...  There is no Windows based vSphere Client available.  But hold it, the KB shows support for vCenter 6.5, how can that be?

Well, here's a little known fact.  IF you have the 6.0 Update 2 version of the OLD Windows based vSphere Client installed, you can actually use it to connect to vSphere 6.5!  Well, kind of, you CAN connect to an ESXi 6.5 host but NOT a vCenter 6.5 server.  So again we are stuck.

OK, so the real answer is to use the command line. 
You need to remove the VM information from the vCenter database. 
One easy way is with PowerCLI 6.5 Release 1, you need to:
  1. Connect to vCenter with a connect-viserver <VC FQDN>
  2. Issue the command get-vm | select name so you can see the VM in question
  3. Issue a remove-vm <VM name> to remove the orphaned VM 
  4. Re-run the original command to verify it's gone and view the inventory!

We start with this VM:
 
We list VMs in VC inventory & Delete the selected VM & Re-list:
 
And you can see the VM is now gone from inventory!

 
So, I've mentioned to my students before, although you can do the vast majority of what you need using a GUI, you may need some command line skills to do certain things when the GUI is lacking.

Never too late to learn PowerShell with PowerCLI for vSphere 6.5! 


No comments:

Post a Comment

Thanks for your comment!