PoshCode Archive  Artifact Content

Artifact 94503c3f202f356130bd78e03a59ec678b483c42d6dda49e716694b3da5c938b:

  • File Scom2012-Maintenance-Mod.ps1 — part of check-in [6330b2c6f7] at 2018-06-10 13:44:46 on branch trunk — Script to put several machines into maintenance mode on your OpsMgr2012 instance. (user: NinjaTechie size: 1504)

# encoding: ascii
# api: powershell
# title: Scom2012 Maintenance Mod
# description: Script to put several machines into maintenance mode on your OpsMgr2012 instance.	
# version: 0.1
# type: script
# author: NinjaTechie
# license: CC0
# x-poshcode-id: 4697
# x-archived: 2013-12-16T12:32:27
# x-published: 2013-12-13T13:25:00
#
# Don’t forget to create the Computers.txt file with the servernames in it!
#
#########################################
# MaintenanceMode.ps1
# Created by NinjaTechie 2013-12-12
# http://ninjatechie.net/
# Simple script to place several servers
# into maintenance mode at the same time
#
#########################################
 
$OMServer = "operationsmanagerserver.contoso.local"
$domain = "contoso.local"
$minutes = 240
$computers = '.\Computers.txt'
$class = "Microsoft.Windows.Computer"
$comment = 'Scheduled Maintenance'
 
Import-Module OperationsManager
New-SCOMManagementGroupConnection $OMServer
 
$class = Get-SCOMClass -Name $class
$startTime = [System.DateTime]::Now.ToUniversalTime()
$endTime = [System.DateTime]::Now.AddMinutes($minutes).ToUniversalTime()
 
$ComputerNames = Get-Content $computers
 
foreach ($name in $ComputerNames) {
 $instance = Get-SCOMClassInstance -Class $class | ? { $_.Name -eq ($name + "." + $domain) }
 "Putting " + $name + " into maintenance mode..."
 $instance.ScheduleMaintenanceMode($startTime, $endTime, "PlannedApplicationMaintenance", $comment , "Recursive")
 Start-Sleep -s 2
}