Powershell script to remove only the primary management server and new primary management server under the agent control panel --"microsoft monitoring agent "

Chetan rms 21 Reputation points
2021-10-14T18:10:53.767+00:00

Hi All,

We have noticed couple of scom agent server had wrong reporting primary management server in the control panel-microsoft monitoring agent.
Kindly help us with powershell script to update the primary management server in control panel .

Note - management group should be same

System Center Operations Manager
System Center Operations Manager
A family of System Center products that provide infrastructure monitoring, help ensure the predictable performance and availability of vital applications, and offer comprehensive monitoring for datacenters and cloud, both private and public.
1,602 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. AlexZhu-MSFT 6,591 Reputation points Moderator
    2021-10-15T02:44:23.277+00:00

    Hi,

    For this query, we can remove the existing management group and add new one using the similar powershell script.

    Note: we need change the script to cater for the real environment, for example, the mangement group name, the primary management server, etc.

    	$mma1 = New-Object -ComObject 'AgentConfigManager.MgmtSvcCfg'  
    	$mma1.RemoveManagementGroup('test02')  
    	if ($? -eq 0)  
    	{  
    		write-host "management group test02 was removed!"  
    	}  
    	$mma1.RemoveManagementGroup('test01')  
    	if ($? -eq 0)  
    	{  
    		write-host "management group test01 was removed!"  
    	}  
    	$mma1.AddManagementGroup('test03' , 'om22.sc.com' , 5723)  
    	if ($? -eq 0)  
    	{  
    		write-host "management group test03 was added!"  
    	}  
    	$mma1.ReloadConfiguration()  
      
    

    screenshot from the lab test before the script is run

    140640-scom-management-group-01.png

    screenshot from the lab test after the script is run

    140695-scom-management-group-02.png

    Alex
    If the response is helpful, please click "Accept Answer" and upvote it.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.