Debugging OpsMgr Scripts
One of the great advantages of OpsMgr 2007 against MOM 2005 is that you can easily test OpsMgr 2007 scripts from the command prompt.
Just go to the C:\Program Files\System Center Operations Manager 2007\Health Service State and open a command prompt.
Type DIR /B /S *.vbs and you find all the scripts that are used on that specific agent. And if you have found your script to debug you can easily run it with cscript and see what happens.
But what if a scripts needs some parameters? Most of the time these are GUIDS and how do you find the right parameters?
A colleague of mine Dirk van Coeverden found an easy way to find these parameters.
Let’s Look at the Operational Database Space Free (%) Monitor.
This Monitor uses a vbscript GetOpsMgrDBPercentageFreeSpace.vbs which needs two parameters to work
So if we want to debug this script we need two parameters; DatabaseServerName and DatabaseName.
How do we find those parameters?
First we need to go to the Authoring Pane in the Opsmgr Console and find the monitor which runs this script.
Then we change the default timeout of the script to something smaller then the default with an override. Say 1 second.
Now we have to wait for this monitor to run again and hopefully see that the script timeouts because of the lower timeout settings. And if the script runs longer than the timeout period an event 21402 – Script ran longer than the timeout period will be created.
Now you can debug the script from the commandprompt with the correct parameters. Don’t forget to remove the overrides.
Comments
Anonymous
January 01, 2003
Courtesy of Stefan Stranger - http://blogs.technet.com/stefan_stranger/archive/2008/12/07/debugging-opsmgr-scripts.aspAnonymous
January 01, 2003
Source: System Center Forum Today I was watching the latest recording of the January 2009 SCUG MeetingAnonymous
January 01, 2003
Courtesy of Stefan Stranger - http://blogs.technet.com/stefan_stranger/archive/2008/12/07/debugging-opsmgr-scripts.aspAnonymous
January 01, 2003
keep in mind that most script have a few characters that are HTMLEncoded, therefore if you copy&past the script from within the XML you will have to do some modifications to let them run on the OS... for example "&" becomes "&" "$gt;" becomes ">" "$lt;" becomes "<" ...etc etc...Anonymous
January 01, 2003
Hi Daniele, Thanks for the info. Forgot to mention that. Regards, Stefan