Removing “Missing” Virtual Machines from System Center Virtual Machine Manager 2008 [R2]
2011 May 27 – 2:02 pmSometimes SCVMM 2008 [R2] has a problem, and it becomes out of sync with the underlying Hyper-V cluster. Usually a quick refresh of the cluster and you’re stored.
Sadly this is not always the case. In the instance where you see duplicate virtual machines you have a bit of an issue on your hands as you can’t migrate that virtual machine to the Hyper-V cluster node that also has the “missing” version of itself.
If you delve deeper, and check the Failover Cluster Manager, you should see that there is only one copy. With that verified the answer is to break out the SQL to fix SCVMM.
- Ideally you’ll want to stop the SCVMM service (VMMService)
- Download and install SQL Studio Manager, or if you’re really hardcore use osql. If you’ve used the default database then you’ll want to connect to COMPUTERNAME\MICROSOFT$VMM$. Otherwise it’ll be where ever it was installed.
- Now there are “2″ solutions we’ve found for this problem. As always backup your database first.
- We found by digging into the database that the virtual machines instances are stored in tbl_WLC_VObject and have an ObjectState equal to 220. Deleting these very quickly removes the VM. However it does potentially leave other references behind.
- The technet way, which we’d recommend, (see http://technet.microsoft.com/en-us/library/ff641854.aspx), which looks at the same table, however also searches all other tables for references.
- Restart the SCVMM service and you should be laughing all the way to the bank
Just incase Technet ever decides to go away, we’ve put the script from the page referenced above, below.
BEGIN TRANSACTION T1
DECLARE custom_cursor CURSOR FOR
SELECT ObjectId from
dbo.tbl_WLC_VObject WHERE [ObjectState] = 220
DECLARE @ObjectId uniqueidentifier
OPEN custom_cursor
FETCH NEXT FROM custom_cursor INTO @ObjectId
WHILE(@@fetch_status = 0)
BEGIN
DECLARE vdrive_cursor CURSOR FOR
SELECT VDriveId, VHDId, ISOId from
dbo.tbl_WLC_VDrive WHERE ParentId = @ObjectId
DECLARE @VDriveId uniqueidentifier
DECLARE @VHDId uniqueidentifier
DECLARE @ISOId uniqueidentifier
OPEN vdrive_cursor
FETCH NEXT FROM vdrive_cursor INTO @VDriveId, @VHDId, @ISOId
WHILE(@@fetch_status = 0)
BEGIN
DELETE FROM dbo.tbl_WLC_VDrive
WHERE VDriveId = @VDriveId
if(@VHDId is NOT NULL)
BEGIN
DELETE FROM dbo.tbl_WLC_VHD
WHERE VHDId = @VHDId
DELETE FROM dbo.tbl_WLC_PhysicalObject
WHERE PhysicalObjectId = @VHDId
END
if(@ISOId is NOT NULL)
BEGIN
DELETE FROM dbo.tbl_WLC_ISO
WHERE ISOId = @ISOId
DELETE FROM dbo.tbl_WLC_PhysicalObject
WHERE PhysicalObjectId = @ISOId
END
FETCH NEXT FROM vdrive_cursor INTO @VDriveId, @VHDId, @ISOId
END
CLOSE vdrive_cursor
DEALLOCATE vdrive_cursor
-----------------
DECLARE floppy_cursor CURSOR FOR
SELECT VFDId, vFloppyId from
dbo.tbl_WLC_VFloppy WHERE HWProfileId = @ObjectId
DECLARE @vFloppyId uniqueidentifier
DECLARE @vfdId uniqueidentifier
OPEN floppy_cursor
FETCH NEXT FROM floppy_cursor INTO @vfdId, @vFloppyId
WHILE(@@fetch_status = 0)
BEGIN
DELETE FROM dbo.tbl_WLC_VFloppy
WHERE VFloppyId = @vFloppyId
if(@vfdid is NOT NULL)
BEGIN
DELETE FROM dbo.tbl_WLC_VFD
WHERE VFDId = @vfdId
DELETE FROM dbo.tbl_WLC_PhysicalObject
WHERE PhysicalObjectId = @vfdId
END
FETCH NEXT FROM floppy_cursor INTO @vfdId, @vFloppyId
END
CLOSE floppy_cursor
DEALLOCATE floppy_cursor
----------------
DECLARE checkpoint_cursor CURSOR FOR
SELECT VMCheckpointId from
dbo.tbl_WLC_VMCheckpoint WHERE VMId = @ObjectId
DECLARE @vmCheckpointId uniqueidentifier
OPEN checkpoint_cursor
FETCH NEXT FROM checkpoint_cursor INTO @vmCheckpointId
WHILE(@@fetch_status = 0)
BEGIN
DELETE FROM dbo.tbl_WLC_VMCheckpointRelation
WHERE VMCheckpointId = @vmCheckpointId
FETCH NEXT FROM checkpoint_cursor INTO @vmCheckpointId
END
CLOSE checkpoint_cursor
DEALLOCATE checkpoint_cursor
-------------------------
---------Clean checkpoint
DELETE FROM dbo.tbl_WLC_VMCheckpoint
WHERE VMId = @ObjectID
exec [dbo].[prc_VMMigration_Delete_VMInfoAndLUNMappings] @ObjectId
DECLARE @RefreshId uniqueidentifier
exec [dbo].[prc_RR_Refresher_Delete] @ObjectId, @RefreshId
DELETE FROM dbo.tbl_WLC_VAdapter
WHERE HWProfileId = @ObjectId
DELETE FROM dbo.tbl_WLC_VNetworkAdapter
WHERE HWProfileId = @ObjectId
DELETE FROM dbo.tbl_WLC_VCOMPort
WHERE HWProfileId = @ObjectId
DELETE FROM dbo.tbl_WLC_HWProfile
WHERE HWProfileId = @ObjectId
DELETE FROM dbo.tbl_WLC_VMInstance
WHERE VMInstanceId = @ObjectId
DELETE FROM dbo.tbl_WLC_VObject
WHERE ObjectId = @ObjectId
FETCH NEXT FROM custom_cursor INTO @ObjectId
END
CLOSE custom_cursor
DEALLOCATE custom_cursor
COMMIT TRANSACTION T1

It saves you money on power, hardware and in some cases because of how Microsoft’s licensing works, we’ve actually reduced the number of licenses that some of our customers had to buy. In early 2007, we started hosting systems and services online – both ours and one of our very first customer’s. It could be said that we were at the forefront of “cloud computing”, mere weeks before the term was coined.
