How to forcefully remove a Virtual Machine from the SCVMM admin console

fixMy buddy Jonathan Jordan recently came across an interesting issue and wrote up a great solution, and since he’s out today I thought I’d take the liberty of posting it.  If you ever find yourself in a position where you tried to remove a VM but it ended up being stuck in a state of limbo then this one’s for you:

========

Issue: A VM has been removed from SCVMM but still appears in the VMM Admin Console. The VM may have been removed in Hyper-V, SCVMM, or Cluster Administrator. When the VM is right clicked on there are two choices: Repair and Delete. Neither work.

Environment:
Windows 2003 with SCVMM 2007
Windows 2008 with SCVMM 2008

Resolution: If after attempting to remove the VM through normal means the machine name is still present, perform these steps:

> Method 1: Locate the .XML file for the machine and delete it.
– On the host that the VM ran on (or hosts if you are unsure which one), at a command prompt:
     Type the drive letter to change to such as C: and hit enter, then…
         dir *.xml /s | find /i “vm name”
– Replacing “vm name” with the name of the VM, this will search a volume for the .XML file that describes the VM
– Move the .XML file to a location that SCVMM does not use for hosted VMs or Library files
– Refresh SCVMM Admin Console

> Method 2: Force removal of VM with PowerShell.  If Method 1 did not work, follow the steps below then refresh the SCVMM Admin Console:

– In the SCVMM Admin Console click the ‘PowerShell’ button. Type ‘A’ for ‘Always’ if prompted by security
– Test PowerShell (this will just list information so that you will know that PowerShell is working properly):
     Get-VMMServer -ComputerName localhost
– This should just list out some VMM info

– Remove VM: Replace “VM Name” with the name of the VM as it appears in SCVMM
$VM = Get-VM -Name “VM Name”
Remove-VM -VM $VM -Force

Note: If the virtual machine still exists as an .XML file as mentioned in Method 1, refresher will repopulate the VM as being present