Debug Microsoft Operations Manager (MOM) scripts either from the local computer or a remote computer by using Microsoft Visual Studio®.NET. After the debugger is connected to the MOM service, you can step through scripts, set breakpoints, view the call stack, examine variables and objects, and use other debugging features in the Visual Studio® .NET development environment. You can debug scripts running on either the MOM Management Server computer or an agent computer.
To support remote debugging, install the full set of Visual Studio® .NET debugging components on the computer running the script.
To install the remote debugging components on an agent computer or a Management Server
The default settings on the MOM Management Server and agents do not support attaching a debugger to the running MOM scripts. You must enable debugging through the Windows registry.
For scripts that run on agent computers, enable debugging on each agent computer that you are debugging. If a script runs on the Management Server, enable debugging on the Management Server computer. This also allows you to debug agent scripts that are running on the Management Server.
To turn debugging on and specify which scripts to debug
To disable debugging, change EnableActiveDebuggingto 0.
NoteDisable debugging after you have finished troubleshooting the problem. Enabling debugging will decrease performance, and other users could attach debuggers to the MOMService.exe process and lock threads for extended periods of time.
Attaching the Debugger to MOM
To attach the debugger to an agent or management server
- Start the Visual Studio .NET integrated development environment.
- On the Toolsmenu, click Debug Processes.
- In the Processesdialog box, in the Namebox, type the name of the computer running the scripts.
- In the Available Processeslist, select MOMService.exe, and then click Attach. Debug scripts on only one agent at a time.
- In the Attach to Processdialog box, from the list of program types to debug, select Script, and then click OK. Check boxes for all other program types should be cleared.
- In the Debugged Processeslist, select the MOMService.exeprocess, click Break, and then click Closeto save settings.
- Wait for a script matching the DebugEnabledScriptsregistry value to run.
To end the debugging session and detach from the MOM service, press Shift+F5.
Debugging the Script
The first script matching the name or wildcard pattern specified in the DebugEnabledScriptsregistry entry opens in Visual Studio® .NET. You can use the commands on the Debug menu. You can also view the data displayed in the various debugging windows, such as the Localswindow and the Call Stackwindow. For more information about debugging with Visual Studio® .NET, see the Visual Studio® .NET documentation.
When debugging MOM scripts, use the following guidelines:
- If script execution is paused for long periods of time as you debug the code, expect MOM to raise alerts indicating that your script did not run to completion in a timely manner. These alerts can be ignored while debugging.
- If the other scripts do not match the DebugEnabledScriptsregistry key, or you press Stepor Goin the debugger, attaching the debugger locks the thread responsible for running your script until the debugging is complete. A locked script thread will not prevent other scripts using other available threads from running , but it does decrease performance.
- If a second instance of a script is started before you finish debugging the first instance, the second instance is prevented from running if it must wait longer than five minutes for the first instance to complete. If any script is prevented from running because of a debugging session or other causes, a MOM alert is raised.
- If you must restart the MOM service, first detach the debugger from the MOM process. Reattach the debugger to the new MOM process after it has started. If you do not explicitly detach the debugger, it might not detect that the service process has stopped.
- If you step through a script that has opened in the debugger until it exits, and the next script to open in the debugger is the same script, the debugger will break into the script. Press F5(the Continuecommand) to complete its execution, unless you want to step through the script again.