Hi all,
Totally new to Powershell and would like some help.
i have script to put all Agents behind a SCOM Gateway into Maintenance Mode:
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"
}
(Thanks to Leon Laude for his help).
However, I need to modify this where I want to let the user to 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"
and from there the script will run as normal.
Can someone help me out with this?