Script to add SCOM agent management group


We wanted to change how SCOM agents is installed and configured. That involved some scripting. As a part of the process we add a management Group to the agent after it is installed. SCOM 2016 is also released now so if you want to migrate instead of upgrading, you can use this script to add an additional MG.

Script will have two mandatory parameters management server and management Group name. A Third parameter is optional, which is the port number and defaults to 5723. You can save the below script as Add-SCOMManagementGroup.ps1


    Adding management group to agent

    Adding first or additional management group to agent. for example use this to multihome agent when migrating to a new management group.

    Add-SCOMManagementGroup.ps1 -ManagementServer SCOM01.domain -MGMTGroupName SCOMMG

    Adds SCOMMG to the agent and set SCOM01 as primary management server. Default port 5723

    Add-SCOMManagementGroup.ps1 -ManagementServer [Primary MS] -MGMTGroupName [Management group name] -port [INT]

    Adds SCOMMG to the agent and set SCOM01 as primary management server and set port you specify

    Author: Martin Ehrnst /Intility AS



   [int]$Port = "5723"


Write-Warning "This will restart the agents health service"

#Adding MG to the agent
$Agent = New-Object -ComObject AgentConfigManager.MgmtSvcCfg
$Agent.AddManagementGroup("$MGMTGroupName", "$ManagementServer", "$Port")}

Write-host "An error occured please se exeption message:"

Write-error $_.Exception.Message

get-service HealthService | Restart-Service

Write-Host "Agent connected to the following management groups"



Engage by commenting