Use PowerShell to Remove a Stubborn VM

Posted On 2014-08-02 by dwirch
Tags: Powershell Scripting Tip Windows
Views: 3705

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 the Author

has posted a total of 190 articles.

Comments On This Post

By: AnonymousCoward
Date: 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:

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

Do you have a thought relating to this post? You can post your comment here. If you have an unrelated question, you can use the Q&A section to ask it.

Or you can drop a note to the administrators if you're not sure where you should post.

Your IP address is:

Before you can post, you need to prove you are human. If you log in, this test goes away.

Code Links