ServiceNow workflow, Powershell and JSON
ServiceNow workflow, Powershell and JSON

ServiceNow provides ITSM solutions and products:

  • Configuration Management Database
  • Edge Encryption
  • Knowledge Management
  • Performance Analytics
  • Reporting
  • Service Catalog
  • Service Portal Designer
  • Subscription Management
  • Visual Task Boards
  • Workflow

The last feature is very interesting. Each workflow can contain “activities”. These activities can be Powershell scripts. If you have already written some Powershell scripts in a workflow the following tip will be useful.

Let’s go with an example.


In that example, the workflow is triggered when a user account entry in ServiceNow is changed by specifying a reset password is required. The tasks/activities are the following:

  • test if the Active Directory user account is existing
  • get the distinguishedname of the user account
  • ask confirmation
  • reset the user account password

The first activity tests if the user account exists by using the email address set in the ServiceNow user account entry


In that activity, a Powershell array is created ( $myarray ) and is converted to JSON. The JSON output is saved in the workflow scratchpad variable called exch_addn. The JSON output is like the following:

    "SID":  {
                "BinaryLength":  28,
                "AccountDomainSid":  {
                                         "BinaryLength":  24,
                                         "AccountDomainSid":  "S-1-5-21-412345679-1123456781-812345678",
                                         "Value":  "S-1-5-21-412345679-1123456781-812345678"
                "Value":  "S-1-5-21-412345679-1123456781-812345678-19780"
    "DistinguishedName":  "CN=USER1,OU=Users,OU=Dept,DC=domain,DC=local"

The next activity:


On that activity, you now understand the power of ServiceNow and Powershell. The JSON array created before has been translated to variables to be used in that script. The JSON objects SID and DistinguishedName are now real Powershell variables called $SID and $DistinguishedName.

It is now your turn to play with that feature !



ServiceNow workflow, Powershell and JSON

Leave a Reply

Your email address will not be published.