Guys, i am stuck in another Authoring issue. Planning for a 2016 migration i have created a management pack wich have some agent/Health service tasks to add and remove management Groups.
The problem is that I want to restart the healhtservice after i have finished management Group configuration. I have seen some VB scripts to do this in a task, but i want to do it within the same task adding or removing MG’s. Until now i have tried to realoadConfiguration within the script, calling a CMD using net-stop and net-start without any luck
The script and task does work. but fails in the console since HS is stopped
Easially remove management group from agent
Remove one connected management group from agent. Use in migration and/or test environments etc
Remove-SCOMManagementGroup.ps1 -MGMTGroupName SCOMMG
Removes the specified MG from agent and restarts the health service.
Author: Martin Ehrnst /Intility AS
Write-Host "This will remove $MGMTGroupName from agent. All monitoring will stop."
#Getting MG and removes if exist
$api = new-object -comObject MOM.ScriptAPI
$api.LogScriptEvent("Remove-SCOMManagementGroup.ps1", 1001, 4, "Removing agent from $MGMTGroupName Workflow initiated from OpsMgr Console")
$Agent = New-Object -ComObject AgentConfigManager.MgmtSvcCfg
$MG = $Agent.GetManagementGroup($MGMTGroupName)
Write-Verbose "Could not find specified Management Group"}
Write-host "An error occured please se exeption message:"
Write-Host "Successfully removed $MGMTGroupName"
This is the same issue that the MS Flush Health cache task has – if the health service has stopped it is unable to report completion. The only way around it I’ve found is to restart the service “outside” of the task, by scheduling a self-deleting Task schedular task to restart the service a few seconds after the task ends, or starting a child process that sleeps before restarting the service, etc.
The task will report success, but you won’t really know if it worked until you wait and see if the agent starts/stops communicating with the management group.
As an aside, is the thinking here that you want to delegate the rollout/cleanup of agents to non-scom admins? The reason i ask is that the discovery wizard is smart enough to handle multi-homing, and when instructed to uninstall will only remove it’s current MGMT group if more than one is configured. This was how most 2007 -> 2012 migrations I’ve been involved in occurred.