1

I'm using PartialMonitoringObject.StopMaintenanceMode to set maintenance modes on Microsoft System Center Operations Manager 2007 R2, check here. No matter what I do, it seems to be ignoring the end time and ending my maintenance window immediately no matter what I specify. The code looks like this:

foreach (string SCOMServer in SCOMServers)
{
    ReadOnlyCollection<PartialMonitoringObject> windowsComputerObjects;          
    ManagementGroup managementGroup;
    MonitoringClass windowsComputerClass;               
    managementGroup = new ManagementGroup(SCOMServer);           
    windowsComputerClass = managementGroup.GetMonitoringClass(SystemMonitoringClass.WindowsComputer);
    windowsComputerObjects = managementGroup.GetPartialMonitoringObjects(new MonitoringObjectGenericCriteria("Name='" + ServerFQDN + "'"), windowsComputerClass);


    foreach (PartialMonitoringObject windowsComputerObject in windowsComputerObjects)
    {
        if (windowsComputerObject.InMaintenanceMode)
        {
            windowsComputerObject.StopMaintenanceMode(DateTime.UtcNow.AddMinutes(DelayInMinutes),Microsoft.EnterpriseManagement.Common.TraversalDepth.Recursive);
            //  windowsComputerObject.ScheduleMaintenanceMode(DateTime.UtcNow,DateTime.UtcNow.AddMinutes(DelayInMinutes)
            RetVal = true;
        }
    }

    `
dbc
  • 104,963
  • 20
  • 228
  • 340
Jason
  • 121
  • 8

1 Answers1

0

Not sure why the StopMaintenanceMode command doesn't work as documented, but changed the code to use UpdateMaintenanceMode instead, and it now does what I need it to do.

foreach (PartialMonitoringObject windowsComputerObject in windowsComputerObjects)
                {
                    if (windowsComputerObject.InMaintenanceMode)
                    {
                        if (DelayInMinutes == 0)
                        {
                            windowsComputerObject.StopMaintenanceMode(DateTime.UtcNow, Microsoft.EnterpriseManagement.Common.TraversalDepth.Recursive);
                        }
                        else
                        {
                            windowsComputerObject.UpdateMaintenanceMode(DateTime.UtcNow.AddMinutes(DelayInMinutes), MaintenanceModeReason.PlannedOther, null, Microsoft.EnterpriseManagement.Common.TraversalDepth.Recursive);
                        }

                        RetVal = true;
                    }
                }

`

Jason
  • 121
  • 8