-
Notifications
You must be signed in to change notification settings - Fork 1
/
set-scommaintenancebulk.ps1
32 lines (32 loc) · 1.61 KB
/
set-scommaintenancebulk.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
[CmdletBinding(
SupportsShouldProcess=$true
)]
Param(
$ManagementServer = 'ms1.contoso.local',
[int32]$DurationMinutes = 60,
[Parameter(Mandatory=$true)]
[ValidateSet('PlannedOther','PlannedHardwareMaintenance','PlannedHardwareInstallation','PlannedOperatingSystemReconfiguration','PlannedApplicationMaintenance')]
[string]$Reason,
[string]$Comment='CalismaVar',
[string]$ServerListPath = 'C:\temp\MMServers.txt'
)
try {
Import-Module OperationsManager -ErrorAction stop -verbose:$False
New-SCOMManagementGroupConnection -ComputerName $ManagementServer -ErrorAction Stop
}
Catch {
throw "Couldt not connect to $ManagementServer. Error: $($_.Exception.Message)"
}
$ServerNames = Get-Content $ServerListPath
$Time = (Get-Date).addMinutes($DurationMinutes)
$Instance = @(Get-SCOMClass -Name "Microsoft.Windows.Computer" | Get-SCOMClassInstance | ? { $_.DisplayName -in $ServerNames} )
$Watcher = @(Get-SCOMClass -Name Microsoft.SystemCenter.HealthServiceWatcher | Get-SCOMClassInstance | ? { $_.DisplayName -in $ServerNames} )
$AllOBjects = $Instance + $Watcher
Foreach ($Server in $AllOBjects) {
if ($pscmdlet.ShouldProcess($Server.FullNAme, "Starting maintenance mode for $DurationMinutes minutes"))
{
#Start-SCOMMaintenanceMode -Instance $Server -EndTime $Time -Comment $Comment -Reason $Reason -
#$instance.ScheduleMaintenanceMode([datetime]::Now.touniversaltime(),([datetime]::Now).addminutes($windowDuration).touniversaltime(), "$windowReason", "$windowsComment" , "Recursive")
$Server.ScheduleMaintenanceMode((Get-DAte).ToUniversalTime(),$Time.ToUniversalTime() , $Reason, $Comment , "Recursive")
}
}