Back in the SCOM 2007 days there was a nice SCOM specific utility called MOMClean.exe that could be used to remove a corrupted agent which could no longer be removed via standard methods like add/remove programs or command line based uninstall. While I don’t come across corrupted agents very often when I do it is usually when a customer is trying to install an update release .msp file and the update mysteriously fails. More often than not the underlying issue is a corrupt agent, and when we try to repair/uninstall/reinstall the agent we hit a brick wall where the standard uninstall methods refuse to work.
There is no official Microsoft SCOM specific tool for cleaning up SCOM 2012/2016 agents, but you can still use a similar approach with a slightly different generic tool.
First go to:
Save the file:
Run the troubleshooting utility:
Select Microsoft Monitoring Agent – Click Next:
Select Yes, try uninstall:
And hopefully success:
In a perfect world you should now be able to go into the SCOM console – delete the associated agent object, and then either rediscover and deploy a new agent, or manually install a new agent depending on how the agent was previously installed.
If reinstalling the agent fails after successfully running the uninstall tool you want to check the following:
Get-Service “System Center Management APM”
If the uninstall was successful you should see a message like “Cannot find any services with service name”
If the services are still present you can run the following to forcibly remove the services:
sc delete healthservice
sc delete “System Center Management APM”
You should also check the registry and confirm the following keys have been removed successfully:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft Operations Manager
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\System Center Operations Manager
If you have confirmed all the above and you still can’t discover/install a new agent after deleting the old agent object from the console run the following T-SQL against the OperationsManager Database:
DECLARE @GroomingThresholdUTC datetime
DECLARE @BatchSize int
SET @GroomingThresholdUTC = getutcdate()
SET @Batchsize = 250
EXEC dbo.p_DiscoveryDataPurgingByTypedManagedEntityInBatches @GroomingThresholdUTC, @BatchSize
EXEC dbo.p_DiscoveryDataPurgingByRelationshipInBatches @GroomingThresholdUTC, @BatchSize
EXEC dbo.p_DiscoveryDataPurgingByBaseManagedEntityInBatches @GroomingThresholdUTC, @BatchSize
Now try the install again and you should be all set.