question

saiyadrahim-9078 avatar image
0 Votes"
saiyadrahim-9078 asked LeonLaude commented

SCOM2012R2 - Put Agents behind Gateway in Maintenance Mode

I have a need to shut down a scom Gateway from old vCenter to new vCenter Environment.
To do this I need to put all Agents behind this Gateway in Maintenance Mode.

Have been trying with this Pshell but didn't work:

Import-Module OperationsManager

$Time = ((Get-Date).AddMinutes(10))
Get-SCOMAgent | where {$_.PrimaryManagementServerName -eq 'GatewayServerName'}|Select DisplayName | Get-SCOMClassInstance | Start-SCOMMaintenanceMode -passthru -EndTime $Time -Comment "Server Migration."


Can someone help in identifying what is a best way to put all Agents behind a Gateway/Management Server in to MM mode.

msc-operations-managermsc-essentials
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

LeonLaude avatar image
0 Votes"
LeonLaude answered LeonLaude edited

Hi,

I've created a script below that should be what you're looking for:

 Import-Module OperationsManager
    
 $Time = ((Get-Date).AddMinutes(10))
 $ErrorActionPreference = 'SilentlyContinue'
 $InstanceClass = Get-SCOMClass -Name "Microsoft.Windows.Computer"
 $Agents = Get-SCOMAgent | where {$_.PrimaryManagementServerName -eq 'Gateway server name'} | Select DisplayName
     
 Foreach($Agent in $Agents){
     $Instance = Get-SCOMClassInstance -Class $InstanceClass | Where-Object {$_.DisplayName -match $Agent.DisplayName}
     Start-SCOMMaintenanceMode -Instance $Instance -EndTime $Time -Comment "Server Migration." -Reason "PlannedOther"
     
         #Checking Maintenance Mode
         $Agent
         Get-SCOMMaintenanceMode -Instance $Instance | select ManagementGroup,User,StartTime,ScheduledEndTime,Reason,Comments | fl
 }

(If the reply was helpful please don't forget to upvote or accept as answer, thank you)


Best regards,
Leon

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

saiyadrahim-9078 avatar image
0 Votes"
saiyadrahim-9078 answered LeonLaude commented

Hi Leon,
That worked perfectly.

Need your help in modifying this if I want to let the user choose which Gateway/Mgmt Server to target.

If i put my values in a variable like this:

$NthGateway="Server1"
$SthGateway="Server2"
$PrimaryMgtServer="Server2"
$SecondaryMgtServer="Server4"

Have the script ask:

"Select SCOM Mgmt/Gateway"

  Press '1'  for Server1"
  Press '2'  for Server2"
  Press '3'  for Server3"
  Press '4'  for Server4"

Would you be able to help me out with a proper script to do this?

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

For general PowerShell questions, I would suggest asking in the dedicated PowerShell forum over here:
https://docs.microsoft.com/en-us/answers/topics/windows-server-powershell.html

0 Votes 0 ·