Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in RPA by (12.7k points)

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 PowerShell Variables 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

0 votes
by (29.5k points)

hi, you are very close to solution, first thing you need to do is add a return function to your poweshell script, you can refer to the code below  

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

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

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

Then, just use this script directly in the Invoke Powershell activity. Note that the most important part here is the Output property, you can just access the text provided by the user by accessing output(0).ToString().

Return output from Powershell script to UIPath using Invoke power shell
Intellipaat-community
by
Can anyone help me on below code, its running in powershell but its throwing error in uipath

param([string] $fol_path)
Add-Type -AssemblyName "System.IO.Compression.Filesystem"
function folp
{
    
    (Get-ChildItem $fol_path).FullName|select-string ".xml"
}
folp

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Jul 10, 2019 in RPA by noah kapoor (5.3k points)

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...