locked
Setting all entities to maintenance based on a particular class RRS feed

  • Question

  • Hi,

    I'm searching for a help from the ps-chiefs:

    Imagine you have a custom class where all servers and services are consilidated in SCOM (e.g. sitename as class). If the switch for this site will fail (e.g. with ping check) all monitored entities behind this swich (defined via the custom class) should go to maintenance.

    Is there anybody who can tell me how to do that? I'm sure that's really hard to realize.

    Thanks for any input! Really.

    Alex

    Sunday, October 3, 2010 4:08 PM

Answers

  • Hi.  Here's a PS script that will take a class display name as a parameter, and place all instances of that class in MM for the specified number of minutes.  I guess you could have this run as a recovery to a ping monitor on the switch, so it would place all objects in MM when the ping monitor goes critical.  You can get your class display name by running get-monitoringclass | select DisplayName,Name | sort DisplayName | more

    #Connect to the RMS server and initialize the command shell
    $rmsServerName = 'RMSServerName'
    add-pssnapin "Microsoft.EnterpriseManagement.OperationsManager.Client";
    Set-Location "OperationsManagerMonitoring::";
    $mgConn = New-ManagementGroupConnection -connectionString:$rmsServerName;
    Set-Location $rmsServerName;
    
    $sClass = $args[0]
    $nMinutes = $args[1]
    $sComment = $args[2]
    
    #Set the start and end time variables
    $startTime = [DateTime]::Now
    $endTime = $startTime.AddMinutes($nMinutes)
    
    #Get the class and any instances of the class
    $Class = get-monitoringclass | where {$_.DisplayName -eq $sClass}
    $Instances = get-monitoringobject -monitoringclass:$Class
    
    #Set the maintenance window
    if($Instances -is [Array])
    {
    foreach($Instance in $Instances)
    {
     New-MaintenanceWindow -startTime:$startTime -endTime:$endTime -reason:'PlannedOther' -monitoringobject:$Instance -comment:$sComment
    }
    }
    else
    {
     New-MaintenanceWindow -startTime:$startTime -endTime:$endTime -reason:'PlannedOther' -monitoringobject:$Instances -comment:$sComment
    }
    

    Layne
    • Proposed as answer by Nicholas Li Tuesday, October 5, 2010 8:56 AM
    • Marked as answer by Nicholas Li Friday, October 8, 2010 3:32 AM
    Monday, October 4, 2010 3:13 PM

All replies

  • Hi.  Here's a PS script that will take a class display name as a parameter, and place all instances of that class in MM for the specified number of minutes.  I guess you could have this run as a recovery to a ping monitor on the switch, so it would place all objects in MM when the ping monitor goes critical.  You can get your class display name by running get-monitoringclass | select DisplayName,Name | sort DisplayName | more

    #Connect to the RMS server and initialize the command shell
    $rmsServerName = 'RMSServerName'
    add-pssnapin "Microsoft.EnterpriseManagement.OperationsManager.Client";
    Set-Location "OperationsManagerMonitoring::";
    $mgConn = New-ManagementGroupConnection -connectionString:$rmsServerName;
    Set-Location $rmsServerName;
    
    $sClass = $args[0]
    $nMinutes = $args[1]
    $sComment = $args[2]
    
    #Set the start and end time variables
    $startTime = [DateTime]::Now
    $endTime = $startTime.AddMinutes($nMinutes)
    
    #Get the class and any instances of the class
    $Class = get-monitoringclass | where {$_.DisplayName -eq $sClass}
    $Instances = get-monitoringobject -monitoringclass:$Class
    
    #Set the maintenance window
    if($Instances -is [Array])
    {
    foreach($Instance in $Instances)
    {
     New-MaintenanceWindow -startTime:$startTime -endTime:$endTime -reason:'PlannedOther' -monitoringobject:$Instance -comment:$sComment
    }
    }
    else
    {
     New-MaintenanceWindow -startTime:$startTime -endTime:$endTime -reason:'PlannedOther' -monitoringobject:$Instances -comment:$sComment
    }
    

    Layne
    • Proposed as answer by Nicholas Li Tuesday, October 5, 2010 8:56 AM
    • Marked as answer by Nicholas Li Friday, October 8, 2010 3:32 AM
    Monday, October 4, 2010 3:13 PM
  • Thank you very much, Layne, for your support!

    Regards

    Alex

    Tuesday, October 12, 2010 1:20 PM
  • $endTime = $startTime .AddMinutes($nMinutes

    This also supports:

    AddSeconds()

    and

    AddHours()

    You might also want a script that ends the maintenance window also? ;-)

    Tuesday, October 12, 2010 2:04 PM