Thursday, July 02, 2009

opsmgr maintenance mode reporting update

Figures… roughly 15 seconds after posting OpsMgr Maintenance Mode report, I found a better way to get my collection of “inMaintenanceMode” objects.  I wouldn’t call this script ‘light’ by any means but at least I query more directly.


param (





#Initializing the Ops Mgr 2007 Powershell provider

add-pssnapin "Microsoft.EnterpriseManagement.OperationsManager.Client" -ErrorVariable errSnapin;

set-location "OperationsManagerMonitoring::" -ErrorVariable errSnapin;

new-managementGroupConnection -ConnectionString:$rootMS -ErrorVariable errSnapin;

set-location $rootMS -ErrorVariable errSnapin;


#create my array for output


$colOut = New-Object System.Collections.ArrayList


#set query criteria and get collection of objects in Maintenance

$criteria = new-object Microsoft.EnterpriseManagement.Monitoring.MonitoringObjectGenericCriteria("InMaintenanceMode=1")

$objectsInMM = (Get-ManagementGroupConnection).ManagementGroup.GetPartialMonitoringObjects($criteria)



#loop to populate the array

foreach ($mm in $objectsInMM) {

      $MWin = $mm.getmaintenancewindow()


      #create an object to hold our variables

      $out = "" | select Name,Path,DisplayName,FullName,StartTime,ScheduledEndTime, Reason, Comments, User, LastModified

      $out.Name = $

      $out.Path = $mm.Path

      $out.DisplayName = $mm.Displayname

      $out.FullName = $mm.Fullname

      $out.Starttime = $Mwin.Starttime

      $out.ScheduledEndTime = $MWin.ScheduledEndTime

      $out.Reason = $MWin.Reason

      $out.Comments = $MWin.Comments

      $out.User = $Mwin.User

      $out.LastModified = $Mwin.LastModified


      #add to our array




#change providers for file work


#spit to csv

$colOut | Export-Csv $filename

No comments:

Post a Comment