IT Process Automation

Expand all | Collapse all

Quotes in parameter to PowerShell operator

Jump to Best Answer
  • 1.  Quotes in parameter to PowerShell operator

    Posted 02-06-2017 12:44 PM

    I have a powershell script which accepts a JSON string as an input. The script works fine when I run it outside of Process Automation.

     

    When I call it within process automation, it strips out all the quotes in JSON...

     

    I am calling the parameter surrounded by "'" + Process.my_var + "'"



  • 2.  Re: Quotes in parameter to PowerShell operator

    Posted 02-06-2017 01:45 PM

    Also, for reference, using PAM 4.2.2



  • 3.  Re: Quotes in parameter to PowerShell operator
    Best Answer

    Posted 02-06-2017 02:09 PM

    Ian, if you are just entering into a script some code you have to specifically tell process automation how to deal with special characters such as quote marks, else they will be interpreted as code.

    Quote get a bit tricky as they are the escape character.   It maybe that you simply need an additional set of quotes to escape the quotes you want or you could replace the quotes with "

     

    Please see our KB on Special Characters in Process Automation



  • 4.  Re: Quotes in parameter to PowerShell operator

    Posted 02-06-2017 02:32 PM

    What I'm using is the "Parameters" section of the Run Script operator. I am trying to pass the JSON that way... I wouldn't expect PAM to strip out the quotes



  • 5.  Re: Quotes in parameter to PowerShell operator

    Posted 02-09-2017 12:21 PM

    Hi,

     

    I've often faced the same problem myself, I basically work around it in one of two ways depending on the situation:

     

    1. Really complex stuff that needs to get passed to a PowerShell script
    2. Fairly simple stuff (but has special characters/formatting)

     

    For #1, I end up writing the string to an SQL scratch table that I keep for just such a purpose, and then read the data from the SQL table into the PowerShell script by passing it the row ID.  I just found for really complex strings it was much easier than trying to deal with escaping or replacing characters.

     

    For #2, I use string replacement in CAPA, and then in PowerShell to reverse the changes.

    So an example with a simple JSON string:

    Process[OpName].TestJSON = '{"fields":{"customfield_11600":"305455","customfield_13501":"338492"}}';
    Process[OpName].TestJSON = Process[OpName].TestJSON.replace(/"/g,"~~");

     

    I would pass Process[OpName].TestJSON to my PowerShell script as a parameter, and then i the PowerShell script I would reverse the change with $args.Replace("~~","""")

     

    Here is the Parameter:

     

    The PowerShell script I used for this example is:

    write-host $args
    write-host $args.Replace("~~","""")

     

    And here is the output from the scriptOutput:

     

    I wish there was an easier way to interact with PowerShell and pass parameters and secure passwords, but I have yet to find one (let me know if you do).

     

    Hope this helps,

    Ian