How to Add a Script to a Workflow

 

Updated: May 13, 2016

Applies To: System Center 2012 SP1 - Service Manager, System Center 2012 R2 Service Manager, System Center 2012 - Service Manager

The Activity Library includes specialized activities that incorporate Windows PowerShell scripts, VBScript scripts, or command-line scripts into workflows. Use a script activity to import the content of the script and to define the parameters that the script requires to run. The System Center 2012 – Service Manager Authoring Tool creates a task in the management pack to manage the script and store the script content and parameters.

Service Manager does not verify the script parameters; therefore, you have to ensure that the script logic handles validation. Also, when you create an incident with an extended property and do not provide a value for the extended property, the value of the parameter is not parsed, and it is passed as $Data/Property.

Script activities run as a separate process from the workflows; however, they also run under the security context of the Service Manager Workflow account.

Use the following procedure to add a script to a workflow.

To add a script to a workflow

  1. In the Management Pack Explorer, expand Workflows, right-click the workflow that you want, and then click Edit. This opens the workflow in the authoring pane.

  2. In the Activities Toolbox pane, locate the activity group Script Activities and its subgroup Generic Script Activities. Drag the script activity that you want to use to a position between the workflow start and workflow end icons or between two existing activities.

  3. Set the script activity properties:

    1. In the Details pane, click any of the properties in the Activity Inputs category, and then click the ellipses () button that appears next to the property.

    2. In the Configure a Script Activity dialog box, click Import Script. In the Import dialog box, select the script file that you want to use, and then click Open.

      Warning


      After you import a script for a script activity, if you click Import Script again, any new script that you import completely replaces the previous script.

    3. Click Script Properties. To create a parameter for the script, click New, and in the Name column, type a name.

      Note


      For VBScript script and command script activity, there is no Name column.

    4. To set a value for the parameter, in the Value column, type a constant value. If appropriate for the parameter, type switch characters such as ‘/t’, which is typical for command scripts.

    5. To bind the parameter to another property so that the parameter obtains its value from that property, click the corresponding ellipses () button. In the Bind ‘Parameter’ to Activity Property dialog box, select the property that you want to use.

    6. If you are working with a script that requires Windows PowerShell snap-ins in order to run, in the Windows PowerShell snap-ins box, type the names of the snap-ins, separated by semicolons.

    7. Click OK to close the Configure a Script Activity dialog box.

See Also

The Activity Library
Adding or Removing Workflow Activities