PowerShell for SCSM: Use PowerShell Scripts in Workflows
Xapity PowerShell Activity provides a central repository to hold PowerShell scripts - located in the
Library section of Service Manager. We soon realised that customers would like to use these scripts in custom workflows created in the SCSM Authoring Tool. We updated Xapity PowerShell to support this ability and this post explains the steps involved.
Using a custom workflow can sometimes be better than adding the an activity to the Work Item - it allows you to have specific criteria that triggers the workflow and it cannot be accidently deleted. You have always been able to create a custom workflow that uses PowerShell, but integrating the workflow with the Script Library makes managing scripts a lot easier.
By using a PowerShell Script from the library all your scripts can be centrally managed and updated. Updating a PowerShell workflow becomes a lot easier, just edit the script in the library and the workflow will use it the next time it triggers. And yes, updating in the Management Pack isn't hard, but it is a lot nicer to do it in the script library and for new administrators it is a lot less daunting when starting out with SCSM.
Using a Xapity PowerShell Activity script in a workflow also allows you to use the run as and PS credentials options on the script. This can be very useful when executing the script against other systems , eg AD where the SCSM workflow account may not have full rights.
The steps to do call a Library script are very simple. The high level steps are:
Create a blank workflow Management Pack (with the criteria to trigger the workflow)
Edit the XML to add the PowerShell Script GUID and assembly name (see below for the exact xml code to use)
And that's it.
Example PowerShell Workflow using Script from Library
In this example I will create a custom PowerShell workflow that triggers when a new Change Request is created. The workflow will run a PowerShell Script from the library that copies the parent Change Request description to all the activities on the new Change Request.
Create a New Workflow Management Pack
Step 1: Using the SCSM Authoring Tool create a new Management Pack
Step 2: Then create a new Workflow in the Management Pack
Step 3: The Workflow wizard will start. First name the Workflow
Step 4: In this example I want to use Criteria to trigger the workflow rather than a scheduled time.
Step 5: Choose the Work Item class and set the event (new item created) and additional trigger criteria. I have added an additional criteria where the title had a keyword in it for testing purposes (not visible in the screenshot below)
Step 6: Summary of the Workflow.
Step 7: Save the Management Pack - there is no need to enter anything else. This is enough for us to now edit the Management Pack xml and add the PowerShell script GUID and assembly name.
PowerShell Script GUID
Step 8: Get the PowerShell Script GUID from the script library. Highlight the script in the library window and then from the preview pane select and copy the script GUID.
Edit Management Pack XML
Step 9: Open the Management Pack XML file - there will be other files created, but we only need the XML file. Go to the WriteActions section of the XML and look for AssemblyName and WorkflowParameters.
Step 10: Relace the XML code with this section - adding the Script GUID to the WorkflowParameter
<WindowsWorkflowConfiguration> <AssemblyName>Xapity.PowerShellActivity.Workflows</AssemblyName> <WorkflowTypeName>Xapity.PowerShellActivity.Workflows.RunPowerShellScript</WorkflowTypeName> <WorkflowParameters> <WorkflowArrayParameter Name="ItemID" Type="guid"> <Item>$Data/BaseManagedEntityId$</Item> </WorkflowArrayParameter> <WorkflowArrayParameter Name="ScriptID" Type="guid"> <Item>Enter_Script_ID_Here</Item> </WorkflowArrayParameter> </WorkflowParameters>
It should look like this after:
Save and Import
Step 11: Save the Management Pack
Step 12: Import the Management Pack into SCSM and test.
Using the Xapity PowerShell Activity central PowerShell script library in custom PowerShell workflows provides an easier way to manage and update your workflows. It gives a quick way to check the script details which makes troubleshooting easier.
Download a free 30 day trial today and try it out: Xapity PowerShell Activity
Xapity PowerShell Activity The Xapity PowerShell Activity is an Activity for SCSM that enables PowerShell scripts to be run in SCSM workflows. Automate more of your processes directly in SCSM. Scripts are stored and updated from a central script repository. The scripts execution output can be viewed and if a failure occurs, an Email Notification can be sent.
Xapity - Innovative Software for SCSM - Discover our Products