Tasks - Part 3: Command Line Console Tasks

Tasks - Part 3: Command Line Console Tasks

  • Comments 9
  • Likes

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”)

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • Hi Travis

    The problem is when I insert  User Comment as a parameter, the output only shows the first word of the comment. How to solve this?

  • When you add that particular parameter, you can wrap it in quotes.

    "$parameterfromSCSM$"

  • Hi,

    Is there a possibility to create such Tasks as management packs and Import it?

    Regards

    Tony

  • @Tony -

    Yes, these tasks are stored in management packs.  You can select which management pack to store them in on the first screen in the wizard (see above).

  • Why in gods green earth would you want to show a newbie this?

  • Hi Travis

    can we edit incident console task output Windows? For example resolve task window or escalated task window?

  • @ Firat Yasar -

    If by 'Edit' you mean customize, no, sorry, that's not possible.

  • thank you for respose.

    by the way i want yo use set first response chekbox on my workflow or my runbook. BUt i didnt find that checkbox class. i want to put thet check box on incident form. this is posible?

  • Can you point me to information that will assist me in creating a task for our techs that will resolve or a complete a work item after the auto-workflow runs on it?  I would like to develop a quick-entry form for our techs to record work that has already been completed.  (We call them drive-bys).  The way the workflow runs in SM, they cannot create and resolve a work item in one session. They have to create the work item, wait for the workflow to activate it, and then return to the form to resolve or complete the work item.  Thank you.