Translate

Wednesday, June 12, 2013

SCOM 2012 SP1 Power shell script for Maintenance Mode for group of servers at once and using Batch file

This blog will help putting group of computers in maintenance mode with just two double click in SCOM 2012 SP1


Three files needed

1)Server names in txt file
2) Powershell script
3) Batch file for execution

Prerequisites: This script needs to run in Management Server with admin or SCOM admin privileges

1

First create a txt file with your server names or group of servers

server1.domain.com
server2.domain.com
server3.domain.com
server4.domain.com

2

Now create a script named it script.ps1 

script content will be as below

_________________________________________________________________________________
Import-module -name OperationsManager;
new-SCOMManagementGroupConnection -ComputerName Localhost;
$Class = get-SCOMclass | where-object {$_.Name -eq "Microsoft.Windows.Computer"};
$time = [DateTime]::Now;
$service = get-content d:\psscript\Servers_1AM.txt | where{$_}
foreach ($i in $service)
{
echo "$i";
$Instance = get-SCOMClassInstance -class $Class | Where-Object {$_.Displayname -eq "$i"};
Start-SCOMMaintenanceMode -instance $Instance -endtime $time.addMinutes(15) -reason "Plannedother" -comment "Test of MM for AppPool";
echo "Starting maintenance mode";
}
_______________________________________________________________________________

This script will than be passed to power shell in batch file for execution



3

Now create a batch file servergroup1.bat, this file will help you with a double click your entire group will be put under maintenance mode


________________________________________________________________________________

powershell.exe -noexit d:\locationof script\script1.ps1                                                                                  _________________________________________________________________________________

Post your question or comment

No comments:

Post a Comment