System Center Operations Manager

Broadcasting live from Redmond, Washington

Console Task Execution with Flexibility

We may run into a situation where we want to execute a console task within OpsMgr based on some condition, like if a file exists, run it otherwise execute another file. Without the If-condition which is not supported by the <Task>, how can we achieve that? Well there is a workaround. Command line has an IF command through which you can do that.

IF [NOT] ERRORLEVEL number command
IF [NOT] string1==string2 command
IF [NOT] EXIST filename command

It also supports ELSE. However, for it to work, it has to occur on the same line as the command.

IF [NOT] EXIST filename (command) ELSE (command)

Adding the IF statement after the CMD.EXE (or %COMSPEC%) will give you much flexibility executing applications based on some criteria, as opposed to directly running the application.

 

For Example

<CommandLine>%COMSPEC% /c IF EXIST C:\MyFile.exe (C:\MyFile.exe) ELSE (C:\MyOtherFile.exe)</CommandLine>

 

Published Thursday, August 14, 2008 10:27 PM by SajidQayyum

Comments

 

Mother said:

Sajid is one of our MP developers and just got his author access on the MOM Team Blog. Good to see. http://blogs.technet.com/momteam/archive/2008/08/14/console-task-execution-with-flexibility.asp

August 15, 2008 2:09 AM
New Comments to this post are disabled

About SajidQayyum

SDE @ SCOM

This Blog

Syndication


© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Microsoft
Page view tracker