--Query 1
--First get the Base Managed Entity ID of the object you think is orphaned/bad/needstogo:
select * from BaseManagedEntity
where fullname like '%computername%'
--Query 2
--Next input that BaseManagedEntityID into the delete statement
--This will delete specific typedmanagedentities more gracefully than setting IsDeleted=1
DECLARE
@EntityId uniqueidentifier;
DECLARE
@TimeGenerated datetime;
-- change "GUID" to the ID of the invalid entity
SET
@EntityId = 'GUID';
SET
@TimeGenerated = getutcdate();
BEGIN TRANSACTION
EXEC dbo.p_TypedManagedEntityDelete
@EntityId,
@TimeGenerated;
COMMIT TRANSACTION
--Query 3
--Check to make sure the IsDeleted field of your BME now = 1
select * from BaseManagedEntity
where fullname like '%computername%'
--Query 4
--Get an idea of how many BMEs are in scope to purge
SELECT count(*)
FROM BaseManagedEntity
WHERE IsDeleted = 1
--Query 5
--This query statement for SCOM 2012 will purge all IsDeleted=1 objects immediately
--Normally this is a 2-3day wait before this would happen naturally
--This only purges 10000 records. If you have more it will require multiple runs
--Purge IsDeleted=1 data from the SCOM 2012 DB:
DECLARE
@TimeGenerated DATETIME,
@BatchSize INT,
@RowCount INT
SET
@TimeGenerated = GETUTCDATE()
SET
@BatchSize = 10000
EXEC p_DiscoveryDataPurgingByRelationship
@TimeGenerated,
@BatchSize,
@RowCountEXEC p_DiscoveryDataPurgingByTypedManagedEntity
@TimeGenerated,
@BatchSize,
@RowCountEXEC p_DiscoveryDataPurgingByBaseManagedEntity
@TimeGenerated,
@BatchSize,
@RowCount