SCOM SDK – PowerShell – Creating monitor

 

icon_sdkOne of my customers wanted to monitor a 3rd party solution by monitoring events and asked if it`s possible with SCOM. As you probably know it`s one of the easiest tasks in SCOM to create monitors to monitor events on event viewer for specific or bunch of servers.

I was told to send them instructions to create a monitor based on Windows events. I started to get screenshots from create management pack and create monitor wizards, and then creating a group for the servers need to be monitored and finally overriding my monitor to enable monitoring for this specific computer group. At the end I realized it was about 30 page screenshots. Instead of sending these screenshots I though it would be much easier and sexy to send them a single PowerShell script to create a monitor. I thought SCOM Shell would have these cmdlets.

I was wrong.

Unfortunately, SCOM Shell doesn`t have any supported shell to create a unit monitor for Windows events. Then I decided to check SCOM SDK.

https://msdn.microsoft.com/en-us/library/hh329086.aspx

That was the first time for me to deal with SDK with PowerShell. SDK is much more powerful than PowerShell but you need to figure out how to deal with objects and methods.

There is an example to create a unit monitor by using SCOM SDK but as you may realize it`s written in C#. That was a good starting point for me.

https://msdn.microsoft.com/en-us/library/hh329015.aspx

So I started my journey, spent couple of hours to create my PowerShell script that uses SCOM SDK binaries. You can find the script below.

Please note that this is really an ugly script, no error handling, structure or sexy functions. This is just a sample to deal with SDK. If you are interested in to learn how to deal with SDK using PowerShell, it`s a good chance to open my script and C# example and see the integration between them.

Also SCOM MVP Tao Yang has done great job with Automating OpsMgr series on his blog http://blog.tyang.org/ .

He also shared with me an article yet to be written regarding monitor creation using SDK. It`s much more better than my ugly script 🙂 So if you need more details, follow Tao`s automation series.

My ugly script:

https://onedrive.live.com/redir?resid=3CAAB02B9CC620D5!57641&authkey=!AKbaImed7116Ig8&ithint=file%2cps1

 

Leave a Reply

Your email address will not be published. Required fields are marked *

59 − = 55