Yes,
just use:
$snDescription = @'
{subscribed Variable}
'@
Handling potential apostrophe's and quotes in a subscribed variable
Hi,
I am bringing in data from ServiceNow "Description" field. Later on I have a powershell .NET activity that uses this subscribed variable from the previous activity.
But how would I handle the possibility that someone may type an apostrophe or a quote character in the description?
I first spotted this with a test I am doing "Andrew's Test" which of course the script failed when assigning that variable within single quotes. I resolved that by changing the single quotes in the script variable assignment to double quotes.
But thinking about this, this is now just going to fail if someone has a double quote, for the same reason.
So, the correct way would be to handle this properly regardless.
If I am doing something like this...
$snDescription = "{SUBSCRIBEDVARIABLEID}"
How can I capture within that if there are single or double quotes and escape them before assigning? Would I just have to do like...
"{SUBSCRIBEDVARIABLEID}".Replace(""", """") - I know this is wrong, but is the idea right? Or if not, how could I do this?
Thanks
Andrew
System Center Orchestrator
2 answers
Sort by: Most helpful
-
Stefan Horz 3,466 Reputation points
2022-01-18T20:30:04.89+00:00 -
Andrew Perry 21 Reputation points
2022-01-17T18:14:33.117+00:00 Just wanted to come back on this.
The resolution for me was to use HERE-Strings in the script around the published data.
Thanks to Chris who also seems to have had the exact same issue...
https://www.concurrency.com/blog/w/using-here-strings-in-an-orchestrator-powershell-s