Handling ConvertFrom-Json in PowerShell
We found a way to partially solve the problem for slashes as follows:
$SRDesc1_Prep = $SR.Description1
$SRDesc1_formatted = $SRDesc1_prep -replace '\\','\\'
$UserResponses = ConvertFrom-Json $SRDesc1_formatted
However, the Orchestrator Runbook still fails if someone enters a double quote into the description field:
I can't find a good way around it since the PowerShell would need to look inside of the double quotes for another single quote. I was wondering if anyone had encountered a similar issue or knows of a better way to handle this?
Thank you!
Answers
Hi,
maybe another approach could be to replace all characters (except valid ones) with a space - or remove them.
this example replaces all characters which are NOT in the list below with a space
$newTitle=$newTitle -replace '[^a-zA-Z0-9\-[\]]', ' '
hope this helps
Geoff, how would we add a Regex to the description prompt? I haven't heard of using that before.