Struggling to configure a PowerShell one-liner. Input and Output parameters

Hi folks,

I’ve spent an anomalous amount of time trying to configure a near-trivial one-liner to take a DataTable and convert it into JSON by means of “$dataTable | select $dataTable.Columns.ColumnName | ConvertTo-Json” commandlet chain.

Here’s why:

  1. the activity configuration is documented, of course, but there are no examples.
  2. Frank Schikora recorded a tutorial and wrote a blog post for the cases of single commandlet and a script, string variables are used there in building one-liners on the fly, but not other types.
  3. I couldn’t find how to interoperate between PowerShell $var syntax and UiPath VB variables.
  4. It takes a non-trivial effort to troubleshoot type conversions in the output: I need a string, but what’s the syntax to output ONE string where a collection is expected?

Any comments will be appreciated.


Is it something like this you are trying to accomplish? PowershellDatatable.xaml (8.2 KB)

1 Like

Thank you, @ptrobot, It looks almost exactly the same as what I’m trying to build. Can’t see the config of the output in the screenshot (seems to be the main question here), will check the XML. An explanation of what decisions you made to choose what goes where and why - would be even more helpful.

In your solution, you iterate the results. Why was that necessary?
Can’t we avoid the ForEach and simply output the JSON that the powershell returns?

Geez. Looks like the key was to enclose the json variable in square brackets like [json] and use Collection explicitly. Wonder why String or Collection couldn’t work.

Looks like the key was to enclose the json variable in square brackets like [json] and use Collection<String> explicitly. Wonder why String[] or Collection<PSObject> couldn’t work.

The output from the Invoke Power Shell activity is always a Collection of TypeArgument. If you don’t want to use a loop, you can get the first result with Output.First.ToString.

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.