Tasks – Part 3: Command Line Console Tasks

This is a continuation of the Tasks series of blog posts:

Tasks – Part 1: Tasks Overview

Tasks – Part 2: Custom Console Tasks for Create, Edit, Delete

In this blog post we will look at creating command line console tasks.  These are the easiest kind of console tasks to create.  The basic idea is to execute any kind of executable file on the file system locally on the computer where the console is running or remotely on a network share via a UNC path.

For this illustration I have created a very simple executable (.exe) which simply writes out the standard output whatever is passed in as the first parameter value.  This is the program:

static void Main(string[] args)
{
    Console.WriteLine(args[0]);
}

Whatever is passed in for the first parameter value is simply written to standard out like this:

image

Now, I’ll show you how to make this Show ID task show up in the console whenever an incident is selected.

  • First, go to the Library workspace in the main console and select the Tasks view.
  • Click on Create Task in the task pane.
  • In the wizard that comes up, give the task a name and choose which MP to store the task in.  In this case because we want the task to show up when we select an incident we should target the incident class.

image

  • Click Next.
  • On the next screen you can choose some categories.  This is another way to control when a task shows up.  For example, if we wanted this task to also show up all the time regardless of what is selected whenever the user is in a view in the Change Management folder we could check the Change Management Folder Tasks checkbox.  We don’t need to do that in this case so just click Next.
  • On the Command Line wizard page we just need to specify the full path to the file that we want to execute.  You can use environment variables here if needed.  In this case, I have just placed the ShowID.exe in the C:\temp directory. 

image

  • Next – we want to specify what the command line arguments should be.  Basically that big textbox there is to contain whatever you would normally type after entering the file to execute.  In our case we need to pass in the ID of the selected object as the first parameter.  To pass the ID of the selected object we need to click the Insert Property button and search for the ID property on the incident class.  Notice how you can select properties of related objects as well. 

image

  • After we click Add a bunch of text is inserted into the textbox for us.

image

You can also do this with named parameters.  You just need to put the parameter name in there before the $….$ value substitution string.

  • Later, when the task is launched by the user, Service Manager will use this funny looking $…$ formatted string to look up the ID property value and insert it at that point in the command line.
  • Next, you can optionally specify a working directory.

image

  • There are two checkboxes here:

image

“Log in action log when this task is run” is used to capture the output of the task and automatically add it as an action log entry in those objects that have an action log (incident and problem for example).

“Show output when this task is run “ is used to decide whether or not to display the output in a popup dialog.  Some tasks like this one we are creating or something like ping.exe will have output and it should be displayed in the UI.  Other tasks have no output like launching an MMC snapin or starting remote desktop.  In those cases the checkbox should be unchecked.

  • The complete configuration should look like this:

image

  • At this point, you can click Next, Create, Close to finish the wizard.
  • If you navigate to an incidents view and select an incident a new task will show up in the task pane:

image

When you click it the incident ID will be passed on the command line and it will be shown in the popup dialog:

image

Here is another example from Marcel Zehner:

Starting the SCCM Remote Control Client from the Service Manager Console

Starting the SCCM Remote Control Client from the Service Manager Console, Part 2 (aka “how to dynamically add information to tasks”)