【问题标题】:Return output from Powershell script to UIPath using Invoke power shell使用 Invoke power shell 将 Powershell 脚本的输出返回到 UIPath
【发布时间】:2018-10-26 22:53:46
【问题描述】:

我正在尝试将输入框中的值从 Powershell 脚本返回到 UI 路径序列。我创建了一个简单的序列作为示例。是的,我知道我可以在 UI Path 中完成所有这些操作,我只是使用一个简单的示例作为尝试测试未来用例的一种方式。这是我的顺序:

“读取文本文件”中的我的文本文件是:

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

UiPath 中的活动如下所示:

我在 Invoke power shell 活动中运行的 psCmd 如下所示:

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{}

我尝试在 Invoke power shell 中的 PowerShellVariables 中将 fooVar 设置为等于 testLocal,然后编写它,但这不起作用。

基本上我想让 fooVar 回到 UI 路径。任何帮助将不胜感激。谢谢!

【问题讨论】:

    标签: powershell uipath


    【解决方案1】:

    你快到了。首先,您的 Powershell 脚本必须返回一个值。以此为例:

    [void][Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')
    
    $title = 'Your title goes here'
    $msg   = 'Your favorite color:'
    
    $text = [Microsoft.VisualBasic.Interaction]::InputBox($msg, $title)
    return $text
    

    这是正在运行的脚本(请注意,我调用了两次,第一次提供了“红色”:

    然后,直接在Invoke Powershell 活动中使用这个脚本。请注意,这里最重要的部分是 Output 属性——在这里,我决定使用字符串数组。当然,由于我们只返回一个值,您可以通过访问output(0).ToString() 访问用户提供的文本。

    【讨论】:

    • 谢谢!你对传入参数有什么建议吗?我能想到的最好方法是将它们保存为变量并将它们实际写入您的 test.ps1(或 .txt)文件,然后调用 cmd。有什么指点吗?
    • 不需要,您可以使用 InvokePowerShell 活动中的参数集合。请注意,您的脚本需要先声明参数。如果遇到问题,请随时提出其他问题。
    • 我已尝试实施您的解决方案。但我得到了错误。你能帮我解决这个问题吗? ***System.Management.Automation.CommandNotFoundException:术语 '[void][Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') $title = '你的标题放在这里' $msg = '你最喜欢的颜色:' $text = [Microsoft.VisualBasic.Interaction]::InputBox($msg, $title) return $text' 未被识别为 cmdlet、函数、脚本文件或可运行程序的名称。检查名称的拼写,如果包含路径,请验证路径是否正确并重试。
    • 找到了我的问题;我还没有设置 IsScript 选项...:)
    • @WolfgangRadl 你能帮我用uipath将参数传递给powershell脚本吗?我已将脚本声明如下。 Param( [Parameter(Mandatory=$true)] [string]$Euser ) return "Deactivating $Euser"
    猜你喜欢
    • 1970-01-01
    • 2017-01-01
    • 1970-01-01
    • 2022-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-30
    • 2012-02-20
    相关资源
    最近更新 更多