Thursday, July 02, 2009

OpsMgr Maintenance Mode report

Updated version:

I needed to report on all items in maintenance mode.  On the web were entries like this one, but that was focused on the computer and agent level, whereas we had lower level objects that were in maintenance mode.  I ended up writing this script.  I still have cleanup to do in my env to make it operational but the basic logic is here.


One thing to note is that each of these items seems to come up 6 or 7 times.  Not sure why at this point but the report is good enough for our purposes and I have other things to do.  B)




#give me all the objects we are monitoring

$colAll = get-monitoringclass | get-monitoringobject


#select out only the ones that are in maintenance mode

$colMM = $colAll | where {$_.inmaintenancemode -eq $true}


#create my array for output

$colOut = New-Object System.Collections.ArrayList


#loop to populate the array

foreach ($mm in $colMM) {

      $MWin = $mm | get-maintenancewindow


      #create an object to hold our variables

      $out = "" | select FullName,UniquePathName,StartTime,ScheduledEndTime, Reason, Comments, User, LastModified

      $out.FullName = $mm.Fullname

      $out.UniquepathName = $mm.UniquePathName

      $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




#spit to csv

$colOut | Export-Csv C:\MaintenanceModeReport.csv


No comments:

Post a Comment