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 commandIF [NOT] string1==string2 commandIF [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.
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