Use PowerShell to Remove a Stubborn VM

By | 2014-08-02

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.

Author: dwirch

Derek Wirch is a seasoned IT professional with an impressive career dating back to 1986. He brings a wealth of knowledge and hands-on experience that is invaluable to those embarking on their journey in the tech industry.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.