Make sure you run the task as a Domain Admin or a local administrator on the server, otherwise the service may stop but may not start back, and you'll have a dead agent. Be careful with DMZ or servers in other domains. This tasks restarts the scom agent after it is finished. I have notes that around 15% of the agents won't start after the restart. This is due the way the agent works, since it is call a restart to itself. That's why I have added a version of the same task that won't restart the agent:
Remove MG info (No Restart) - same as above, but no agent restart. You can use SC or psexec to restart the agents afterwards.
Add MG info to agent - it can be used to fix a mistake or from any MP, add a second MG reference.
Download the MP here and please let me know of any problems you face.