SCOM rehome agents to another management server via powershell?

EE,

I have an issue where a management server keeps crashing and we need to get the agents off.

I'm trying to do it with an article from 2007 but I'm running 2012R2 and the commands are different.

Can someone assist?

$serverfrom = Get-ManagementServer | ? {$_.name -eq "FQDN of the Server you are moving the agents from"}
$agents = Get-Agent -ManagementServer $serverfrom
$serverto = Get-ManagementServer | ? {$_.name -eq "FQDN of the Server you are moving the agents to"}
Set-ManagementServer -AgentManagedComputer:$agents -PrimaryManagementServer:$serverto

$agent = Get-Agent -ManagementServer $serverfrom | ? {$_.name -eq "FQDN of the agent"}
snyderkvAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David Johnson, CD, MVPOwnerCommented:
<#
#########================================================================================================#########
# 
# 
# **  Name: MoveAgentSCOMMgmtServer.ps1
# **  Author: System Center MVP - Steve Buchanan
# **  Date: 5/20/2015
# **  Version: 1.1
# **  Website: www.buchatech.com
# 
# **  Description:
# **  This script can be used to move agents from one management server or gateway server to another. 
# **  There is a common issue "Cannot change SCOM agents Primary Management via the GUI (SCOM Console)".
#
# **  Problem Referneces:
# **  http://www.systemcentercentral.com/forums-archive/topic/moving-agents-from-one-gateway-server-to-another/
# **  https://social.technet.microsoft.com/Forums/systemcenter/en-US/c5214222-0cc3-4da5-a40e-64cbeff91573/r2-cannot-change-primary-management-server?forum=operationsmanagergeneral
#
# **  This script requires PowerShell version 3.0 or hire. To check PowerShell version run $PSVersionTable from a PowerShell window.
# **  This script should be run in an administrative PowerShell console on a SCOM management server. 
# **  You can run this script using: powershell.exe -executionpolicy unrestricted -command .\MoveAgentSCOMMgmtServer.ps1
#
#########================================================================================================#########
#>

###########################
## General Script Settings
###########################

# Error Handling
$ErrorActionPreference = "SilentlyContinue"

####################################
## Begin Script
####################################

Import-Module -Name OperationsManager
$SCOMMS = Read-Host "Enter SCOM Management Server FQDN"
$PrimaryMgmtServer = Get-SCOMManagementServer -Name "$SCOMMS"
$SelectedSCOMAgents = (Get-SCOMagent | Out-GridView -Title "Select the SCOM agents you want to set the management server for." -PassThru)
Set-SCOMParentManagementServer -Agent ($SelectedSCOMAgents) -PrimaryServer ($PrimaryMgmtServer)

Write-Host SCOM agents $SelectedSCOMAgents.DisplayName had their Primary Management set to $SCOMMS. -ForegroundColor Green

# Variable cleanup
Remove-Variable -Name *

Open in new window

https://gallery.technet.microsoft.com/Move-Agent-SCOM-Primary-9927d7a3
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
snyderkvAuthor Commented:
You're the man, thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Center Operations Manager (SCOM)

From novice to tech pro — start learning today.