1

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:

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:

Read Text File

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.

fooVar

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

1 Answer 1

2

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:

powershell messagebox

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().

invoke ps in UiPath

Sign up to request clarification or add additional context in comments.

6 Comments

Thank you! Do you have any advice for passing in parameters? The best way I can think of is saving them as variables and actually writing them to your test.ps1 (or .txt) file and then invoking the cmd. Any pointers?
No need to, you can just make use the parameters collection from the InvokePowerShell activity. Note that your script needs to declare the parameters first. Feel free to ask another question if you run into issues.
I have tried to implement your solution. But I am getting below error. Could you please help me with that? ***System.Management.Automation.CommandNotFoundException: The term '[void][Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') $title = 'Your title goes here' $msg = 'Your favorite color:' $text = [Microsoft.VisualBasic.Interaction]::InputBox($msg, $title) return $text' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
Found my issue; I haven't set the IsScript option...:)
@WolfgangRadl Can you help me with passing parameters to powershell script with uipath. I have declared the script as follows. Param( [Parameter(Mandatory=$true)] [string]$Euser ) return "Deactivating $Euser"
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.