PowerShell: State Changes for a specified Monitor

PowerShell: State Changes for a specified Monitor

  • Comments 2
  • Likes

This week a got a question from a customer about ‘flapping’ taking place from a Monitor. I found out that they meant the State Changes that took place for a newly created Monitor. They found out that for a certain machine the State changed quite often and this was caused by a Recovery Task that was part of this monitor.

So they wanted to know if there was a way to see quickly if a Monitor caused a lot of State Changes. There are quite some SQL queries you can use to have a look at the State Changes taken place in your OpsMgr environment. Just take a look at some of the SQL queries on the weblog of my colleague Jonathan Almquist.

But what if you only want to know the State Changes that took place for a specific Monitor? Again you can use one of Jonathan’s SQL queries and change them to fit your needs. And this is exactly what I’ve done but I also wanted to run the query from the OpsMgr Command Shell. The reason for this was that I easily wanted to retrieve the Monitor Name using the OpsMgr Get-Monitor Cmdlet.

 

So here is the PowerShell script I created. You can change the SQL query if you want, to fit your own needs ;-)

Result screenshot:

image

Have fun with OpsMgr and PowerShell!

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • Nice script.  This is a nice way of building a library for quick access and results in PS.  One thing you'll need to keep in mind is, these scripts will need to be executed under the context of an account that has access to the database. :)

  • Hi Jonathan, you are right about the context of the account running the script. That's why I added, the next lines to the script. You need to have db permissions to the OperationsManagerdw database to run this Script.

    But you could also insert some set-credential cmdlet to change the credentials for access to the operationsmanagerdw database