Narendra,

I use to scripts (.bat) that call a ps1 script to start then stop MM on a per 
group basis. The .bat files and scheduled in the Task scheduler. We also have 
some scripts to raise alerts in the MM fails to start or stop.

StartMMGroup1.bat

powershell "c:\GroupMM.ps1" -groupName:'<GROUP NAME HERE>-minutes:<MINUTES for 
the MM Window> -startMM:$true -comment:'Nightly Power Cycle schedule'

StopMMGroup1.bat

powershell "c:\GroupMM.ps1" -groupName:'<GROUP NAME HERE> -startMM:$false


++ The Main script
GroupMM.ps1
# Get the inputs from the command line syntax

param($groupName,$minutes,$rmsServerName,$startMM,$comment)

$rmsServername = "RMS Server Name Here"

#Load the Operations Manager snapin and connect to the Root Management Server
add-pssnapin "Microsoft.EnterpriseManagement.OperationsManager.Client";
Set-Location "OperationsManagerMonitoring::";
$mgConn = New-ManagementGroupConnection -connectionString:$rmsServerName;

if($mgConn -eq $null)
{
[String]::Format("Failed to connect to RMS on '{0}'",$rmsServerName);
return;
}

Set-Location $rmsServerName;

#Get references to the Group, Windows Computer, Health Service, and Health 
Service watcher classes
$instanceGroupClass = Get-MonitoringClass -Name:System.Group
$windowsComputerClass = Get-MonitoringClass -Name:Microsoft.Windows.Computer
$healthServiceClass = Get-MonitoringClass 
-Name:Microsoft.SystemCenter.HealthService
$healthServiceWatcherClass = Get-MonitoringClass 
-Name:Microsoft.SystemCenter.HealthServiceWatcher

#Get a reference to the PrincipalName property as this will be needed soon
$principalNameProp = Get-MonitoringClassProperty 
-monitoringClass:$windowsComputerClass | where {$_.Name -eq 'PrincipalName'}

#Find the user specified group
$groupInstance = 
(Get-ManagementGroupConnection).ManagementGroup.GetPartialMonitoringObjects($instanceGroupClass)
 | where {$_.DisplayName -eq $groupName}

if($groupInstance -eq $null)
{
                [String]::Format("Group '{0}' not found",$groupName);
                return;
}

#Retrieve all the computers contained in the group.
#This will return both agent as well as agentless managed computers
$computers = 
$groupInstance.GetRelatedMonitoringObjects($windowsComputerClass,[Microsoft.EnterpriseManagement.Common.TraversalDepth]::OneLevel)

#Get the RMS server name. This will be needed in order to avoid putting the RMS 
into maintenance mode
$rmsName = 
(Get-ManagementGroupConnection).ManagementGroup.GetAdministration().GetRootManagementServer().PrincipalName

#Out the number of computers found in the group
[String]::Format("{0} computers found in the '{1}' 
group",$computers.Count,$groupName);

#Iterate through the list of computers and put each computer, its associated 
health service and health service watcher
#into maintenance mode.
foreach($computer in $computers)
{

$computerPrincipalName = 
$computer.GetMonitoringPropertyValue($principalNameProp);

#Only put the computer into maintenance mode if its not the RMS
if([System.String]::Compare($computerPrincipalName,$rmsName,$true) -ne 0)
{

if($startMM -eq $true)
{
                [String]::Format("Starting maintenance mode for: 
{0}",$computerPrincipalName);
}
else
{
                [String]::Format("Ending maintenance mode for: 
{0}",$computerPrincipalName);
}

$healthServices = $computer.GetRelatedMonitoringObjects($healthServiceClass)

$healthService = $healthServices[0]

$healthServiceCriteria = "HealthServiceName='" + $computerPrincipalName + "'"

$healthServiceWatcher = Get-MonitoringObject 
-monitoringClass:$healthServiceWatcherClass -criteria:$healthServiceCriteria

#$startTime = [DateTime]::Now
$startTime = (Get-date).ToUniversalTime()
$endTime = $startTime.AddMinutes($minutes)
$comment = $comment

if($startMM -eq $true)
{
                New-MaintenanceWindow -startTime:$startTime -endTime:$endTime 
-reason:"ApplicationInstallation" -comment:$comment -monitoringObject:$computer
}
else
{
                if($computer.InMaintenanceMode -eq $true)
                {
                                
$computer.StopMaintenanceMode([DateTime]::Now.ToUniversalTime(),[Microsoft.EnterpriseManagement.Common.TraversalDepth]::Recursive);
                }
}

#For agentless managed computers there will be no health service instance
if($healthService -ne $null)
{
                if($startMM -eq $true)
                {
                                New-MaintenanceWindow -startTime:$startTime 
-endTime:$endTime -reason:"ApplicationInstallation" -comment:$comment 
-monitoringObject:$healthService
                }
                else
                {
                                if($healthService.InMaintenanceMode -eq $true)
                                {
                                                
$healthService.StopMaintenanceMode([DateTime]::Now.ToUniversalTime(),[Microsoft.EnterpriseManagement.Common.TraversalDepth]::Recursive);
                                }
                }
}

#For agentless managed computers there will be no health service watcher 
instance
if($healthServiceWatcher -ne $null)
{
                if($startMM -eq $true)
                {
                                New-MaintenanceWindow -startTime:$startTime 
-endTime:$endTime -reason:"ApplicationInstallation" -comment:$comment 
-monitoringObject:$healthServiceWatcher
                }
                else
                {
                                if($healthServiceWatcher.InMaintenanceMode -eq 
$true)
                                {
                                                
$healthServiceWatcher.StopMaintenanceMode([DateTime]::Now.ToUniversalTime(),[Microsoft.EnterpriseManagement.Common.TraversalDepth]::Recursive);
                                }
                }
}
}
}



Peter Hakesley PJH2711-RIPE, CDCT, MBCS

SCC Services

Data Centre Operations - Service Implementation - Enterprise Systems Engineer

SCC Cole Valley 1,
20 Westwood Avenue,
Tyseley,
BIRMINGHAM B11 3RZ

Tel: +44 (0)845 351 0680 xtn 4006
eMail: [email protected]<mailto:[email protected]>
Web : www.scc.com<http://www.scc.com/>

[Description: Description: BCS_Logo]

From: [email protected] [mailto:[email protected]] On 
Behalf Of Narendra Bathula
Sent: 15 February 2014 21:19
To: '[email protected]'
Subject: [msmom] Scheduled Maintenance Mode - SCript/Tool / Sql query required 
urgently -SCOM2007 R2

Maintenace mode for the SCOM 2007 R2 agents is the Big problem for me all the 
time.   I am running with SCOM 2007 R2. Every week we have a server reboot 
schedule maintenance mode for almost 400 servers.  I think this is a big count 
of servers to reboot in signle window and i tried couple of tools available out 
side for maintenance actvitiy but no luck.   none of the tools was not worked 
perfectly....I think it is also problem with microsoft that is why they have 
not included this feaure in the tool where we can not specify the start date 
for schedule activity.

Please suggest me if is there a tool/script/SQL query  to place the bulk agents 
into maintenance mode for scom 2007 R2.

Basically I am looking for Scheduled maintenance activity that could specify my 
start date and time and maintenance end date and time...?.  Thanks in advance.



::DISCLAIMER::
----------------------------------------------------------------------------------------------------------------------------------------------------
The contents of this e-mail and any attachment(s) are confidential and intended 
for the named recipient(s) only.
E-mail transmission is not guaranteed to be secure or error-free as information 
could be intercepted, corrupted,
lost, destroyed, arrive late or incomplete, or may contain viruses in 
transmission. The e mail and its contents
(with or without referred errors) shall therefore not attach any liability on 
the originator or HCL or its affiliates.
Views or opinions, if any, presented in this email are solely those of the 
author and may not necessarily reflect the
views or opinions of HCL or its affiliates. Any form of reproduction, 
dissemination, copying, disclosure, modification,
distribution and / or publication of this message without the prior written 
consent of authorized representative of
HCL is strictly prohibited. If you have received this email in error please 
delete it and notify the sender immediately.
Before opening any email and/or attachments, please check them for viruses and 
other defects.
----------------------------------------------------------------------------------------------------------------------------------------------------




<<inline: image001.jpg>>

Reply via email to