System Center Operations Manager Invalid Management Group Removal

Invalid Management Group Removal

Last updated on March 30th, 2023 at 05:07 pm

Read Time:2 Minute, 37 Second

We recently carried out some work for a client who had a completely ruined installation of System Center Operations Manager (SCOM).

Who had done what to it, we may never know, but it was clear that the only fix was to start again. This was not such a bad thing as they did want to change the name of their Management Group anyway – which secretly lead us to believe that someone had been messing and trying to carry this out, hence the mess of the installation!

We went ahead and carried out a completely new installation of Operations Manager as this is what they wanted, however, if you are an administrator of Operations Manager, you will probably know about the potential for an absolute nightmare here – the old Management Group and the new Management Group now being referenced on the servers and end users machines (although in this case, they only wanted servers being monitored by Operations Manager).

We managed to resolve this issue by using a PowerShell script. We did not write this PowerShell script ourselves and we apologise now for not giving the credit where it is due, but we cannot remember where we got it from – if it’s you, let us know and we will update with credit.

The plan is very simple, go into the Operations Manager server, check for error EventID 20046 in the Event Viewer (which will give you the name of a server trying to report with an invalid Management Group) then edit and run the PowerShell script to remove the reportedly invalid Management Group from that server.

PowerShell Script to Remove SCOM Invalid Management Group

The PowerShell script we used is below, note these variables that you must enter per server:

  • $ComputerName = The server name with the invalid management group
  • $ManagementGroup = The name of the invalid management group
param(
$ComputerName = "SERVERNAME",
$ManagementGroup = "MGMT GROUP NAME"
)

Function Remove-SCOMManagementGroup ($ComputerName)
{
$sb = {
param($ManagementGroup,
$ComputerName)
Try {
$OMCfg = New-Object -ComObject AgentConfigManager.MgmtSvcCfg
} catch {
throw "$ComputerName doesn't have the SCOM 2012 agent installed"
}
$mgs = $OMCfg.GetManagementGroups() | %{$_.managementGroupName}
if ($mgs -contains $ManagementGroup) {
$OMCfg.RemoveManagementGroup($ManagementGroup)
return "$ManagementGroup removed from $ComputerName"
} else {
return "$ComputerName does not report to $ManagementGroup"
}
}
Invoke-Command -ScriptBlock $sb -ComputerName $ComputerName -ArgumentList @($ManagementGroup,$ComputerName)
}
Remove-SCOMManagementGroup -ManagementGroup $ManagementGroup -ComputerName $ComputerName

Once the PowerShell script has completed, you either need to restart the Microsoft Monitoring Agent service (Service Name is: HealthService) on the affected machine or reboot it.

If you then go into your server Control Panel and then into the Microsoft Monitoring Agent applet, you should now see that you only have the corrent new Management Group on there and that the invalid old one has been removed.

System Center Orchestrator

Of course, if you know how to use System Center Orchestrator and you have it installed in your environment, you can setup a new Runbook to check for EventID 20046 and then trigger the PowerShell script from there.

Feedback

If you have any questions or feedback on this guide, we would love to hear from you. You can contact us via our Social Media channels or just leave us a message below in the comments box.

Click to rate this post!
[Total: 0 Average: 0]

Free Subscription

If you want to be notified when we post more quality guides like this one, sign up to our free subscription service and you will receive an email when a new post is live.

Join 441 other subscribers.

No need to worry, we will not be filling your inbox with spam and you can unsubscribe anytime you like.


Leave us a message...

This site uses Akismet to reduce spam. Learn how your comment data is processed.