Search Tools Links Login

Use PowerShell to Remove a Stubborn VM


During a recent cleanup effort in the System Center Virtual Machine Manager console, I found a powered off guest machine.  The status showed the VM as having an "Unsupported Cluster Configuration State".

The recommended action is to repair the state of the virtual machine, then attempt the operation again.  I was able to repair the state by ignoring the last operation, but I was still unable to start or remove the VM from the console.

What gives?

So I found that the VM itself was created outside of SCVMM, utilizing the Hyper-V MMC.  This created the VM with no problem, but it plopped the VM files (configuration, VHD, etc) on a local drive of the node it was created on, then moved into the cluster with with failover cluster manager.

SCVMM then discovered the machine, and noted the invalid configuration, referencing non-clustered storage.  Fine, no problem.  It won't start, so I'll delete it.  BZZZZZ! Nope!

The service account that VMM runs under apparently didn't have rights to the local path where the VM files were stored, so the job failed.  I was able to repair the error in VM, but I couldn't work with the VM in any other fashion through the VMM console.

Okey dokey, I'll simply delete the dead guest from the location in the file system, and remove it from failover cluster manager.  Well, that got me halfway.  The machine was now technically gone, but hmmm, it still is visible in the SCVMM console, even after several cluster refreshes, and I still can't remove it from SCVMM via console.

PowerShell to the rescue! 

To be honest, I wasn't sure this was going to work.  I thought maybe the VMM database was having issues, and I would have to go spelunking around the database and surgically remove the bogus entries directly.

I popped open an elevated PowerShell prompt, and typed the following command:

Remove-SCVirtualMachine -VM "My Virtual Machine Name"

I was rewarded with the a listing of the information about the VM, but no red error messages. Interesting!  So I popped over to the SCVMM console, and lo, the machine was gone.  It worked!

Moral of the story: Don't trust the GUI, but be careful with the weapon that is PowerShell.

About this post

Posted: 2014-08-02
By: dwirch
Viewed: 6,745 times

Categories

Tip

Scripting

Powershell

Windows

PowerShell Code Cache

Attachments

No attachments for this post


Loading Comments ...

Comments

AnonymousCoward posted this comment on 2015-09-22:

~~Thanks for a good post. Sadenly, this didn't work out for me, but it did direct me to the solution.


Since I have VCenter in SCVMM too, and had another VM machine who has the same hostname, I received errors that there are duplicates and I need to be more specific. I found this post from Technet who managed to deleted my specific VM who had issue:


https://technet.microsoft.com/en-us/library/jj647747(v=sc.20).aspx

I ran this:

$VM = Get-SCVirtualMachine -VMMServer "SCVMM_HOSTNAME" | where { $_.VMHost.Name -eq "HYPER-V_HOSTNAME" -and $_.Name -eq "VM_MACHINE_NAME" }

$VM | Remove-SCVirtualMachine -Force

You must be logged in to make a comment.