Return output from Powershell script to UIPath using Invoke power shell

那年仲夏 提交于 2019-12-24 08:18:05

问题


I am trying to get a value from an input box from a Powershell script back to a UI Path Sequence. I have created a simple sequence as an example. Yes, I know I could do this all in UI Path, I am just using an easy example as a way to try and test this for future use cases. Here is my sequence:

My text file from "Read text file" is:

$test = "Desktop/PassingArgs2of2.ps1 -Message foo"
Invoke-Expression -Command $test

The activity in UiPath looks like so:

The psCmd that I am running in the Invoke power shell activity looks like this:

Param(
[parameter(Mandatory=$true)]
[string]
$Message)

try{

    $Global:fooVar = $null

    function Test-InputBox(){
        [void][Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')
        $msg = "fooMsg"
        $title = "fooTitle"
        $localtest = [Microsoft.VisualBasic.Interaction]::InputBox($msg, $title)
        $Global:fooVar = $localtest.ToString()
    }
    Test-InputBox
}
catch{}

I tried setting fooVar equal to testLocal in the PowerShellVariables within Invoke power shell and then writing it, but that did not work.

Basically I want to get fooVar back into UI Path. Any help would be greatly appreciated. Thank you!


回答1:


You're almost there. First, your Powershell script has to return a value. Take this for example:

[void][Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')

$title = 'Your title goes here'
$msg   = 'Your favorite color:'

$text = [Microsoft.VisualBasic.Interaction]::InputBox($msg, $title)
return $text

Here's the script in action (note that I called it twice and provided "red" the first time:

Then, just use this script directly in the Invoke Powershell activity. Note that the most important part here is the Output property - here, I decided to go for an array of strings. Naturally, as we only return a single value, you can just access the text provided by the user by accessing output(0).ToString().



来源:https://stackoverflow.com/questions/53017215/return-output-from-powershell-script-to-uipath-using-invoke-power-shell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!