OpsMgr PowerShell QuickTip: How do I retrieve a list of monitored objects in maintenance mode?

Here’s a great tip from an SCC forum thread this morning that I thought worth sharing.

The Question

How can I retrieve a list of monitored objects currently in maintenance mode in System Center 2012 Operations Manager?

The Answer

This is easily done in a single line of script:

Get-SCOMMonitoringObject | where-object {$_.InMaintenanceMode -eq $true}

Incidentally, the following would also work

Get-SCOMClassInstance | where-object {$_.InMaintenanceMode -eq $true}

And a ‘well done’ to community member bradcaccamo 

The Downside

The negative in this case is that the output is a bit unruly as we see all of the objects hosted by the computer and OS classes that are in maintenance mode


but let’s investigate the options for tidying up the output a bit

Extending This Solution

What if I wanted to retrieve only a list of certain types of objects in maintenance mode?

This would also be easy using the Get-SCOMClass cmdlet.

For example, to retrieve the Windows Computer class (Microsoft.Windows.Computer), we would use:

Get-SCOMClass –Name Microsoft.Windows.Computer

If we add this to the left of our existing one-liner (watch line wrap below), we can filter only class instances that match this qualifier, like so

Get-SCOMClass –Name Microsoft.Windows.Computer | Get-SCOMClassInstance | where-object {$_.InMaintenanceMode -eq $true}

The output is a bit tidier this time, reflecting only Windows Computers in maintenance mode. This could be adjusted to display the class(es) of your choice.


Additional Resources

On a related note, here are a few sample scripts for the OpsMgr 2012 Command Shell 

OpsMgr 2012:See Who is Currently Connected to Your Management Group via PowerShell

Cloning Notification Subscriptions in Operations Manager 2012 using PowerShell [sample script]

OpsMgr 2012: All my Java apps require manual discovery – where do I get BeanSpy and PowerShell install scripts?

OpsMgr 2012: Reset Unit Monitors in Bulk with PowerShell

OpsMgr 2012: Find Computers without the Active Directory Helper Object (OOMADS) with PowerShell

OpsMgr 2012: Disabling Rules and Monitors in Bulk in PowerShell

OpsMgr 2012: Group Maintenance Mode via PowerShell (the way it should be)

OpsMgr 2012: Running a Task in Bulk Using PowerShell

OpsMgr 2012: Automating Agent Discovery and Deployment with PowerShell [sample script]

OpsMgr 2012: Identifying Computers in Active Directory without an OpsMgr Agent Installed [sample script]

OpsMgr 2012 Quick Tip: Finding servers experiencing the most heartbeat failures with PowerShell

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.