Skip to content

Josh's IT-Blog

Information Technology, and other interesting things …

  • Home
  • About
  • Contact
    • Contact
    • Impressum
  • Links
  • Comic Strips

change SCOM agent assignement to other SCOM gateway

Posted on 22. June 202020. October 2020 By Burkard Josh
PowerShell

if you need to change the assignement of a SCOM gateway to another SCOM gateway, you can do this by this script:

<#
    .SYNOPSIS
        This script sets a new Management Point for a SCOM Agent

    .PARAMETER ManagementPoint
        defines the Management Point or Gateway to use

    .PARAMETER ManagementGroup
        defines the Management Group to use

    .EXAMPLE
        Set-ScomManagementPoint.ps1 -ManagementPoint 'gateway.domain.net' -ManagementGroup 'MG001'
#>
Param (
    [string]$ManagementPoint
    ,
    [string]$ManagementGroup = 'MG001'
)
try {
    $SCOMAgent = New-Object -ComObject AgentConfigManager.MgmtSvcCfg
}
catch {
    Write-Output "no SCOM Agent found"
}
if ( -not ( [string]::IsNullOrEmpty( $SCOMAgent ) ) ) {
    Stop-Service -Name HealthService

    $StateDirectory = Get-ItemPropertyValue -Path HKLM:\SYSTEM\CurrentControlSet\services\HealthService\Parameters -Name 'State Directory'

    $CurrentMGs = $SCOMAgent.GetManagementGroups()
    foreach ( $CurrentMG in $CurrentMGs ) {
        try {
            $SCOMAgent.RemoveManagementGroup( $CurrentMG.managementGroupName )
        }
        catch {
            throw "couldn't remove current Management Group '$( $CurrentMG.managementGroupName )'"
        }
    }

    $ChildItems = Get-ChildItem -Path $StateDirectory
    foreach ( $ChildItem in $ChildItems ){
        try {
            Remove-Item -Recurse -Force -Confirm:$false -Path $ChildItem.FullName
        }
        catch {
            throw "couldn't remove '$( $ChildItem.FullName )'"
        }
    }

    $SCOMAgent.AddManagementGroup($ManagementGroup, $ManagementPoint, 5723)

    $SCOMAgent.ReloadConfiguration()

    $MGs = $SCOMAgent.GetManagementGroups()
    foreach ( $MG in $MGs ) {
        Write-Output "$( $MG.managementGroupName ):$( $MG.ManagementServer )"
    }
}

please note, that this script will remove the old assignement and clean up the state directory. if you don’t cleanup the state directory, the agent will after a service restart be assigned again to the old gateway.

Share this:

  • Facebook
  • Twitter
  • Email
  • Print

Post navigation

❮ Previous Post: remove sensitive files from GIT
Next Post: Volatile Registry Keys ❯

About

Author Image
My name is Josh Burkard.
I'm a DevOps Engineer working with one of swiss largest telecom and full-service hosting provider. in my work I have a lot to do with Microsoft server operating systems, System Center, VMware, Microsoft Azure Cloud and other software.
On this site I will write some posts about different technology problems and their solutions.
please note also my tweets and retweets from this area.

Follow me on Twitter

My Tweets

Categories

  • General (12)
  • Hardware (9)
    • Network (8)
      • Cisco (2)
    • Storage (2)
  • Microsoft Azure (1)
    • Automation (1)
  • PowerShell (1)
  • Software (1)
    • Excel (1)
  • System Center (19)
    • SCCM (3)
    • SCDPM (1)
    • SCOM (13)
    • SCSM (1)
    • SMA (1)
  • VMware (8)
  • Windows 2008 R2 (10)
    • Active Directory (7)
  • Windows 2012 R2 (1)
  • Windows 2016 (1)
  • Windows 7 (4)
    • BitLocker (1)
  • WordPress (1)

Links

  • Burkard-Fingerlin Family
  • Swisscom (Schweiz) AG
Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy

Copyright © 2021 Josh's IT-Blog.

Theme: Oceanly by ScriptsTown

loading Cancel
Post was not sent - check your email addresses!
Email check failed, please try again
Sorry, your blog cannot share posts by email.