piątek, 10 lutego 2017

SCOM Agents Migration Part 2. Migrating to Another Server within the Same Management Group

    Sometimes you might have a need to redirect the SCOM Agents to the new infrastructure after changing Management Servers.This can be done from the SCOM Console level, assuming, that:
1. You deployed the SCOM agents via Discovery from the SCOM Console, or you performed a change on the Ops DB necessary in order to be able to manage manually deployed SCOM Agents from the Console
2. The old Management Servers are still active and communicate with your Management Group
    It might happen though, that you have an SCCM Deployment, or any other way of distributing the agent, which for some reasons was not updated after the migration and deployed agents with old settings despite the SCOM infrastructure change. The situation is problematic, because by simply re-installing the agent you will not be able to change the settings. SCOM Agent keeps the old configuration and keeps trying to contact non-existing servers. Recently I posted a solution to migrate the SCOM agents to a new Management Group. You can find it here:

    Unfortunately this solution is not invasive enough to migrate objects within the same Management Group. SCOM is pretty persistent when it comes to keeping the configuration of the agent. When you remove the configuration and then add the new entry for the same Management Group the configuration will revert to the previous one. What needs to be done is the Health Service State flush, and the script in this post is doing this as well
Usage:
     Swap the following strings in the script below with the names from your SCOM infrastructure:
  • _MGName_ - put the name of your Management Group
  • _NewMGServerFQDNName_1_ - put the FQDN of the first new Management Server
  • _NewMGServerFQDNName_2_ - put the FQDN of the second new Management Server
     The code has to be saved as a .vbs file and run on the SCOM client either manually or for instance via SCCM deployment
Additional Notes:
    The script as well as the previous version contains the random seed in order to spread the load between two Management Servers.
Code:
Option Explicit
On Error Resume Next

Dim objMSConfig
Set objMSConfig = CreateObject("AgentconfigManager.MgmtSvcCfg")

Dim oShell
Set oShell = CreateObject("Wscript.Shell")

Dim objMG

oShell.run "CMD /C ""NET STOP HealthService""", 0, true
oShell.run "CMD /C ""RMDIR /S /Q ""C:\Program Files\System Center Operations Manager\Agent\Health Service State.old""""", 0, true
oShell.run "CMD /C ""REN ""C:\Program Files\System Center Operations Manager\Agent\Health Service State"" ""Health Service State.old""""", 0, true


Call objMSConfig.RemoveManagementGroup ("_MGName_")

Randomize
If Rnd > 0.5 Then
    Call objMSConfig.AddManagementGroup ("_MGName_", "_NewMGServerFQDNName_1_",5723)
Else
    Call objMSConfig.AddManagementGroup ("_MGName_", "_NewMGServerFQDNName_2_",5723)
End If

Call objMSConfig.ReloadConfiguration