Using Quotes in Orchestrator PowerShell Activities

Author by Christopher Mank

One really neat thing you can do when using Orchestrator with Service Manager is write some PowerShell activities to configure the output in a format that is much easier for your analysts to read.  Building off of this post where Nate showed you how you can insert Carriage Returns to format your data correctly, there is one additional note we should point out when configuring this. PowerShell interprets single quotes (') very differently from double quotes (").  Although I will not cover all of the differences in this post, what we do want to mention here is that if you use double quotes and your string already contains a double quote (") in it, the script will most likely fail. Let's consider the following scenario to better understand.  We have a Service Request that is created via the portal that asks users to select new hardware/software they wish to purchase.  What we want to do is add some of the data to the Description field.  Using the Carriage Return technique, we have a PowerShell script that looks like this: PowerShell and Orchestrator Carriage Returns and Quotes Double Image Here we are setting the $Desc variable to contain text about who the request is for, a list of all the catalog items selected and the Notes from the SR, all on separate lines. Notice how the Published Data "Notes from Get SR" is encapsulated within double quotes(").  99% of the time, this setup will work just fine.  But what happens if one of the catalog items selected is called (22" Monitor).  See the issue here?  When we use double quotes around this string and the PowerShell activity sees the extra double quotes, it fails and causes the entire Runbook to fail. So how do we fix this?  Super easy actually.  All we need to do is enclose our Published Data variable within singe quotes(') like shown below: PowerShell and Orchestrator Carriage Returns and Quotes Single quotes in PowerShell are interpreted as strings, even though they may contain special characters.  So in our 22" Monitor example, the script works with no issues.  As a general rule of thumb, you should use single quotes, but I recommend you take the time to study a bit on the differences between the two because as you script more things in PowerShell, you will find yourself needing to use both of them depending on the situation.  I hope this helps. Until the Whole World Hears, Christopher

Author

Christopher Mank

Systems Architect