SCOM rehome agents to another management server via powershell?

snyderkv
snyderkv used Ask the Experts™
on
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"}
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016
Commented:
<#
#########================================================================================================#########
# 
# 
# **  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

Author

Commented:
You're the man, thanks

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial