Tuesday, April 24, 2012

[Powershell][OpsMgr 2007] Get All objects in Maintenance Mode using powershell

The need here is to be able to list all objects in Maintenance mode in a management group.

Here is also a very short powershell function you can use :

  1. function ListObjectsInMaintMode {
  2.  $criteria = new-object Microsoft.EnterpriseManagement.Monitoring.MonitoringObjectGenericCriteria("InMaintenanceMode=1")
  3.  $objectsInMM = (Get-ManagementGroupConnection).ManagementGroup.GetPartialMonitoringObjects($criteria)
  4.  $objectsInMM | select-object DisplayName, @{name="ObjectType";expression={foreach-object {$_.GetLeastDerivedNonAbstractMonitoringClass().DisplayName}}},@{name="StartTime";expression={foreach-object {$_.GetMaintenanceWindow().StartTime.ToLocalTime()}}},@{name="EndTime";expression={foreach-object {$_.GetMaintenanceWindow().ScheduledEndTime.ToLocalTime()}}},@{name="Path";expression={foreach-object {$_.Path}}},@{name="User";expression={foreach-object {$_.GetMaintenanceWindow().User}}},@{name="Reason";expression={foreach-object {$_.GetMaintenanceWindow().Reason}}},@{name="Comment";expression={foreach-object {$_.GetMaintenanceWindow().Comment}}}
  5. }
In a powershell shell, connect to a management group and just launch ListObjectsInMaintMode

Result be look like :



This can be really usefull ! :)

This posting is provided "AS IS" with no warranties.

No comments:

Post a Comment