Removing a stuck SCOM Agent or anything else
Once in a blue moon we have issues with certain boxes in our environment where the SCOM (Opsmgr) agent refuses to uninstall or repair itself. I have not managed to work out why this occurs (would assume soemthing went wrong under the hood).
If you remove the entry for the application in the add/remove registry sotre (HKEY_CLASSES_ROOT\Installer\Products\{GUID}) you will be able to re-install SCOM.
The only problem that you face with this approach is going through every subkey looking for the GUID that corresponds to the SCOM agent, so this is where automation comes in handy. As some systems in our environment don’t have PowerShell installed by default I decided to approach this using VBScript.
You can replace the lookingFor variable with any other application that you are struggling with if you would like.
Const HKCR = &H80000000 'HKEY_CLASSES_ROOT strComputer = "." Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv") lookingFor = Ucase( "System Center Operations Manager 2007 R2 Agent" ) foundPath = "" foundKey = False strKeyPath = "Installer\Products" '\\ Start the search oReg.EnumKey HKCR, strKeyPath, arrSubKeys For Each subkey In arrSubKeys '\\ Get a list of all Products and loop through them newSearchPath = strKeyPath & "\" & subkey oReg.GetStringValue HKCR, newSearchPath, "ProductName", productName '\\ Check if we have the corect key If( Ucase(productName) = lookingFor ) Then foundKey = True foundPath = newSearchPath Exit For End If Next '\\ If nothing was found, quit If (foundKey = False) Then Wscript.Echo "There was no key mathing """ & lookingFor & """ found!" Wscript.Quit End If '\\ Confirm that the user wants to drop the key If (MsgBox( "Are you sure you want to delete : " & lookingFor & "?", 36, "Delete Key" ) = 7) Then Wscript.Echo "OK Then" Wscript.Quit End If '\\ Deleting the key and all subkeys Wscript.Echo "Attempting to remove :: " & foundPath deleteRegistryKey HKCR, foundPath Sub deleteRegistryKey( hive, path ) oReg.EnumKey hive, path, delSubKeys If IsArray(delSubKeys) Then For Each subkey In delSubKeys deleteRegistryKey hive, path & "\" & subkey Next End If oReg.DeleteKey hive, path End Sub














