Skip to content

Commit c33e1cf

Browse files
authored
Create Move-ListofAgents.ps1
1 parent 6a61aa8 commit c33e1cf

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# ===============================
2+
# Author: Blake Drumm (blakedrumm@microsoft.com)
3+
# Created: September 30th, 2022
4+
# Modified: September 30th, 2022
5+
# Script location: https://github.com/blakedrumm/SCOM-Scripts-and-SQL/blob/master/Powershell/Agents%20Failover/Move-ListofAgents.ps1
6+
# ===============================
7+
8+
#List of agents to change
9+
$AgentList = @"
10+
SCSM.contoso.local
11+
SQL-SCEM02.contoso.local
12+
"@
13+
14+
#Primary Management Server
15+
$movetoPrimaryMgmtServer = Get-SCOMManagementServer -Name "MS01.contoso.local"
16+
#Secondary Management Server
17+
$movetoFailoverMgmtServer = Get-SCOMManagementServer -Name "MS02.contoso.local"
18+
19+
$i = 0
20+
foreach ($line in ($AgentList -split "`n"))
21+
{
22+
$SCOMAgent = Get-SCOMAgent $line.trim()
23+
foreach ($agent in $SCOMAgent)
24+
{
25+
$i++
26+
$i = $i
27+
#Remove Failover Management Server
28+
Write-Output "($i/$(($AgentList.Trim() -split "`n").Count)) $($agent.DisplayName)`n Removing Failover: $(($agent.GetFailoverManagementServers()).DisplayName -join ", ")"
29+
$scomAgentDetails | Set-SCOMParentManagementServer -FailoverServer $null | Out-Null
30+
#Set Primary Management Server
31+
Write-Output " Primary: $(($agent.GetPrimaryManagementServer()).DisplayName) -> $($movetoPrimaryMgmtServer.DisplayName)"
32+
$scomAgentDetails | Set-SCOMParentManagementServer -PrimaryServer $movetoPrimaryMgmtServer | Out-Null
33+
#Set Secondary Management Server
34+
Write-Output " Failover: $($movetoFailoverMgmtServer.DisplayName)`n"
35+
$scomAgentDetails | Set-SCOMParentManagementServer -FailoverServer $movetoFailoverMgmtServer | Out-Null
36+
}
37+
}

0 commit comments

Comments
 (0)