Friday, June 20, 2014

Duplicate VMs in SCVMM 2012 R2 after Live Migration

After migrating VMs cluster-to-cluster (or from stand-alone host to cluster), you might see duplicate VMs in SCVMM. Both VMs are in running state, properties are identical, you can connect to both of those etc. Everything works, but it does not look good.

This is how it looks like:


So, how to remove duplicates.

Way to detect which one is 'original' and which one is 'duplicate', select VM, check on recent job and see which one has been live migrated. (Actually, it does not seem to matter if you remove duplicate or original, it is just a SCVMM database entry that we are removing. VM actually keeps running even if you remove both of those)

Open properties of that VM and start doing some change, for example like this:

And click 'View Script'

It opens notepad, where we can see ID of this VM in SCVMM database.

And rest is done in SCVMM Powershell. First, use get-vm and check that we get two VMs with different ID.


get-vm <servername>|fl id
Then, we remove duplicate VM with ID that we just checked.
get-vm <servername>|where ID -eq "<ID>"|remove-vm -force

And now important thing, you have to use "-force" switch. Remove-vm (or to be precise, Remove-SCVirtualMachine) without -force, removes all files and configurations of that VM, but when you use -force, it only removes entry from SCVMM database. Obvious, right?

Here is documentation: http://technet.microsoft.com/en-us/library/hh801721.aspx and quote from that page: 'NOTE: When used with the Force parameter, Remove-SCVirtualMachine only deletes the virtual machine from the VMM database. It does not delete the virtual machine itself.'

And why this happens? Well, I don't know. It seems to be a bug in SCVMM. For some reason, sometimes SCVMM 'detects' that new VM has been added to cluster. It happens 15-30 seconds before Live Migration is finished. And when it happens, you get duplicate VMs.

4 comments :

  1. Thanks for this, helped me out!

    ReplyDelete
  2. Thank you. Worked like a charm. Much better than all those other scripts out there.

    ReplyDelete