Scripting in 2007

For scripting in MOM 2005 Brian Wren’s excellent articles ( on how to take all those scripts out there and “MOMifiy” them was essential reading. So there is good news and bad news on scripting in OpsMgr 2007.

The good news is that you do not need all that “stuff” around the scripts (ScriptObject) to make them work in 2007. Nor do you need a special tool (like ResponseTest.exe in MOM 2005 RKit) to test them out outside of OpsMgr. In fact the test is to run the script as a vbs (or js) file using cscript. That is why when you are creating script rules it asks you to give it a name which initially confused me. Although 2007 embeds the script in the XML of the management pack when it is at the agent the script is created using that file name in a directory structure. In 2005 you could see all the scripts. In 2007 that is harder with sealed MPs. (Clive Eastwood has just released a tool to do that here –

You can, however, see all the scripts that are assigned to that agent and look at how the scripts are written for some help. They are on each agent under Program Files, System Center Operations Manager 2007, Health State Service with a directory called Monitoring Host Temporary Files x where x is a number that changes. You will see a directory with a number for each script so it does not seem to matter if you give the script the same name but it would be better if it was unique. If you search on that directory for vbs or js files you will then see them all. Also note that in the wizard if you do not give the script an extension the next button is greyed out. It does not tell you why (very frustrating) but now you know.

The bad news is that there is not much in the way of documentation and examples. The best around at the moment is the SDK. There is a section called “Using OpsMgr Runtime Scripts” at and another section on the scripting objects at Additionally Daniele has a nice screen shot step by step post on creating a script based unit monitor at Note that if you cut and paste the example script you need to change the apostrophes (“) as that causes the script to fail when run. There are also examples of using a script for discovery at

What you will need to get used to, is using “MOM.ScriptAPI” in order to use the script and MOMScriptAPI.CreatePropertyBag Method to store information until you need to assign it to OpsMgr calling the Return method. Programmers among you will recognise the Property Bag concept. Unfortunately not many infrastructure people are programmers – including me.

What I have not found is how to then turn information gathered directly into an alert. Neale (from SystemCenterForum) also mentioned that in one of the news groups and suggested using the MOMScriptAPI.LogScriptEvent Method which allows you to put an event into an event log so that you can create a rule to alert on it. I did think about that but the documentation does say that its use was for checking that scripts are working properly. And in some of the AD scripts they use CreateEvent with a corresponding rule. There must be a better way. If only we had some documentation.

As the script is embedded in the MP it is not obvious how top create one script and use that with multiple rules using parameters like 2005. The documentation hints at being able to do it using “data source module type” but I have not found out how. And unsurprisingly no documentation on it. There is a parameter section which is confusing in itself as it is just a blank window but you can pass context parameters at runtime but you need to know them. Fortunately they are listed in the SDK. Try remembering $Target/Property[Type=’Windows!Microsoft.Windows.Computer’]/PrincipalName$ from the top of your head!

The bottom line is that we need more documentation and examples with clear explanations of what is being used and why. But once we get that then it looks like scripts will be a lot more powerful in 2007 as they run natively as cscript scripts.



  1. Thanks for pointing out the issue with the double quotes – the conversion happenend unintentionally when blogging it 😦
    I’ll try to see if I can fix it…

  2. Btw, I fixed the fancy quotes thing on my blog 🙂

  3. David


    Do you know how to use the output of your script in performance view charts for e.g.

    I am evaluating Ops Mgr 2007. One of our requirements is to monitor the directory and subdirectory size used by each student on our file server. We have different sections folders and under each we have subfolders for students. We will want to monitor the use and have charts representing the % of Disk size used by each folder and subfolder.
    I am also an insfrastructure resource person and I am not that good in programming. I have found a script that monitor file and directory size from Anders Bengtsson @
    but I would like to use the output either to post an alert when threshold is exceeded and also have performance charts displaying usage.

    Thanks for any help and suggestions


  1. musc@> $daniele.rant | Out-Blog » Blog Archive » Create a Script-Based Unit Monitor in OpsMgr2007 via the GUI
  2. System Center Forum - Custom Scripting in Operations Manager 2007
%d bloggers like this: