If you cannot remove cluster object using Virtual Machine Manager GUI or shell, then you need to connect to VMM database using SQL Server Management Studio:
Click the New Query button and remember to choose your VMM database name from the drop-down list (in my case VirtualManagerDB).
First take a look at your cluster objects with the command
SELECT * FROM tbl_ADHC_HostCluster
In my case the second row contains the cluster I want to delete from VMM database. Then you should put your ID to the following code (second row):
DECLARE @ClusterID GUID, @HostID GUID
SET @ClusterID = '2E60A809-F181-4F4E-B3C1-D75B1AE9FFF2'
SELECT @HostID = HostID from dbo.tbl_ADHC_Host where HostClusterID = @ClusterID
DELETE FROM tbl_WLC_VObject WHERE HostId = @HostID
DELETE FROM tbl_ADHC_HostVolume WHERE HostID = @HostID
DELETE FROM tbl_WLC_PhysicalObject WHERE HostId = @HostID
DELETE FROM tbl_ADHC_Host WHERE HostClusterID = @HostID
DELETE FROM tbl_ADHC_HostDisk WHERE HostID = @HostID
DELETE FROM tbl_ADHC_ClusterDisk WHERE OwnerHostID = @HostID
DELETE FROM tbl_ADHC_VmwResourcePool WHERE HostID = @HostID
DELETE FROM tbl_ADHC_VmwResourcePool WHERE HostClusterID = @ClusterID
DELETE FROM tbl_ADHC_ClusterDisk WHERE ClusterID = @ClusterID
delete from tbl_NetMan_HostNetworkAdapterToLogicalNetwork where HostNetworkAdapterID = (select HostNetworkAdapterID
from tbl_NetMan_HostNetworkAdapterToLogicalNetwork as nic2net, tbl_ADHC_HostNetworkAdapter as nic
where nic.HostID = @HostID and nic2net.HostNetworkAdapterID = nic.NetworkAdapterID)
DELETE FROM tbl_ADHC_HostNetworkAdapter WHERE HostID = @HostID
delete FROM tbl_ADHC_VirtualNetwork WHERE HostID = @HostID
delete from tbl_ADHC_ISCSIHbaToTargetMapping where ISCSIHbaID = (SELECT hbaid FROM tbl_ADHC_HostBusAdapter WHERE HostID = @HostID)
delete from tbl_ADHC_ISCSIHbaToPortalMapping where ISCSIHbaID = (SELECT hbaid FROM tbl_ADHC_HostBusAdapter WHERE HostID = @HostID)
delete from tbl_ADHC_HostInternetSCSIHba where ISCSIHbaID = (SELECT hbaid FROM tbl_ADHC_HostBusAdapter WHERE HostID = @HostID)
delete FROM tbl_ADHC_HostBusAdapter WHERE HostID = @HostID
delete FROM tbl_NetMan_InstalledVirtualSwitchExtension WHERE HostID = @HostID
DELETE FROM tbl_ADHC_Host WHERE HostID = @HostID
DELETE FROM tbl_ADHC_HostCluster WHERE ClusterID = @ClusterID
After running this script your cluster should be removed from VMM.
--- Updated 18.04.2017
To remove a stuck host object only (without the cluster) I narrowed down the commands to this (just replace the yellow hostname):
DECLARE @HostID GUID
SELECT @HostID = HostID FROM dbo.tbl_ADHC_Host where ComputerName = 'host.domain.local'
DELETE FROM tbl_WLC_VObject WHERE HostId = @HostID
DELETE FROM tbl_WLC_PhysicalObject WHERE HostId = @HostID
DELETE FROM tbl_ADHC_HostVolume WHERE HostID = @HostID
DELETE FROM tbl_ADHC_HostDisk WHERE HostID = @HostID
DELETE FROM tbl_ADHC_ClusterDisk WHERE OwnerHostID = @HostID
DELETE FROM tbl_ADHC_VmwResourcePool WHERE HostID = @HostID
delete from tbl_NetMan_HostNetworkAdapterToLogicalNetwork where HostNetworkAdapterID = (select HostNetworkAdapterID
from tbl_NetMan_HostNetworkAdapterToLogicalNetwork as nic2net, tbl_ADHC_HostNetworkAdapter as nic
where nic.HostID = @HostID and nic2net.HostNetworkAdapterID = nic.NetworkAdapterID)
DELETE FROM tbl_ADHC_HostNetworkAdapter WHERE HostID = @HostID
delete FROM tbl_ADHC_VirtualNetwork WHERE HostID = @HostID
delete from tbl_ADHC_ISCSIHbaToTargetMapping where ISCSIHbaID = (SELECT hbaid FROM tbl_ADHC_HostBusAdapter WHERE HostID = @HostID)
delete from tbl_ADHC_ISCSIHbaToPortalMapping where ISCSIHbaID = (SELECT hbaid FROM tbl_ADHC_HostBusAdapter WHERE HostID = @HostID)
delete from tbl_ADHC_HostInternetSCSIHba where ISCSIHbaID = (SELECT hbaid FROM tbl_ADHC_HostBusAdapter WHERE HostID = @HostID)
delete FROM tbl_ADHC_HostBusAdapter WHERE HostID = @HostID
delete FROM tbl_NetMan_InstalledVirtualSwitchExtension WHERE HostID = @HostID
delete FROM tbl_ADHC_HostToProcessorCompatibilityVectorMapping WHERE HostID = @HostID
DELETE FROM tbl_ADHC_Host WHERE HostID = @HostID
After running the commands I was able to normally remove the host object right in VMM console.
--- Updated 06.05.2022
Powershell version:
Thank you for this article. I had obtained other scripts that were not working but yours worked for both of my "pending" clusters. Your help is very much appreciated.
ReplyDeleteNice to hear that it worked.
DeleteFantastic article, thank you.
ReplyDeleteNice to hear that it worked. Was your problem related to host only or to the whole cluster?
Deletethis was really helpful to me thank you, I just had to amend it slightly as follows:
ReplyDeleteDECLARE @HostID GUID
SELECT @HostID = HostID FROM dbo.tbl_ADHC_Host where ComputerName = 'server.contoso.com'
DELETE FROM tbl_WLC_VObject WHERE HostId = @HostID
DELETE FROM tbl_WLC_PhysicalObject WHERE HostId = @HostID
DELETE FROM tbl_ADHC_HostVolume WHERE HostID = @HostID
DELETE FROM tbl_ADHC_HostDisk WHERE HostID = @HostID
DELETE FROM tbl_ADHC_ClusterDisk WHERE OwnerHostID = @HostID
DELETE FROM tbl_ADHC_VmwResourcePool WHERE HostID = @HostID
this next part failed for me as two HostNetworkAdapterID were returned
delete from tbl_NetMan_HostNetworkAdapterToLogicalNetwork where HostNetworkAdapterID = (
select HostNetworkAdapterID from tbl_NetMan_HostNetworkAdapterToLogicalNetwork as nic2net, tbl_ADHC_HostNetworkAdapter as nic where
nic.HostID = @HostID and nic2net.HostNetworkAdapterID = nic.NetworkAdapterID)
So i ran
select HostNetworkAdapterID from tbl_NetMan_HostNetworkAdapterToLogicalNetwork as nic2net, tbl_ADHC_HostNetworkAdapter as nic where
nic.HostID = @HostID and nic2net.HostNetworkAdapterID = nic.NetworkAdapterID
got the two HostNetworkAdapterID, then chose one of them and ran
delete from tbl_NetMan_HostNetworkAdapterToLogicalNetwork where HostNetworkAdapterID = '54D441CB-F8E7-4F23-84F4-71817330581C'
then i was able to proceed with the rest of the script.
DELETE FROM tbl_ADHC_HostNetworkAdapter WHERE HostID = @HostID
delete FROM tbl_ADHC_VirtualNetwork WHERE HostID = @HostID
delete from tbl_ADHC_ISCSIHbaToTargetMapping where ISCSIHbaID = (SELECT hbaid FROM tbl_ADHC_HostBusAdapter WHERE HostID = @HostID)
delete from tbl_ADHC_ISCSIHbaToPortalMapping where ISCSIHbaID = (SELECT hbaid FROM tbl_ADHC_HostBusAdapter WHERE HostID = @HostID)
delete from tbl_ADHC_HostInternetSCSIHba where ISCSIHbaID = (SELECT hbaid FROM tbl_ADHC_HostBusAdapter WHERE HostID = @HostID)
delete FROM tbl_ADHC_HostBusAdapter WHERE HostID = @HostID
delete FROM tbl_NetMan_InstalledVirtualSwitchExtension WHERE HostID = @HostID
delete FROM tbl_ADHC_HostToProcessorCompatibilityVectorMapping WHERE HostID = @HostID
DELETE FROM tbl_ADHC_Host WHERE HostID = @HostID
Thank you. I also sometimes need to adjust those queries. Glad, that it worked finally.
DeletePlease, I have this error: Msg 547, Level 16, State 0, Line 5
ReplyDeleteThe DELETE statement conflicted with the REFERENCE constraint "FK_tbl_WLC_PhysicalObject_tbl_ADHC_HostVolume". The conflict occurred in database "VirtualManagerDB", table "dbo.tbl_WLC_PhysicalObject", column 'HostVolumeId'.
try several runs and it should succeed
Delete