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.
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
dwirch has posted a total of 172 articles.
Comments On This Post
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.