UiPath Documentation
activities
latest
false
工作流活动
重要 :
请注意,此内容已使用机器翻译进行了部分本地化。 新发布内容的本地化可能需要 1-2 周的时间才能完成。

Invoke PowerShell

Invoke PowerShell activity that executes a PowerShell command or script with specified input parameters.

UiPath.Core.Activities.InvokePowerShell

描述​

The Invoke PowerShell activity executes a PowerShell command or script with specified input parameters.

备注:

Antivirus policies that restrict PowerShell access may prevent the use of PowerShell-related activities. For example, you cannot use Invoke Workflow File and Invoke PowerShell when rule ID 6151 is enabled in McAfee Endpoint Security.

项目兼容性​

Windows - Legacy | Windows

配置​

  • 命令文本 - 要执行的 PowerShell 命令。此值可以是 cmdlet 的名称,也可以是 PowerShell 脚本的文本。

属性面板​

常见​

  • “出错时继续”- 指定在活动引发错误时是否应继续自动化操作。该字段仅支持“布尔值”(True 和 False)。默认值为 False。因此,如果该字段为空且活动引发错误,系统将停止执行项目。如果该值设为“True”,则无论出现何种错误,系统都将继续执行项目。
    备注:

    如果“Try Catch 异常处理”中包含该活动且“出错时继续”属性的值为“True”,则系统在执行项目时不会捕获任何错误。

  • “显示名称”- 活动的显示名称。

输入​

  • 参数 - PowerShell 命令参数字典。可以使用特定命令 (cmdlet) 或脚本。
    • 特定命令:调用特定命令时,参数名称应与命令参数的名称相符。

例如,如果您使用 Get-Command -Module CimCmdlets 作为输入,则输入值必须为 Get-Command,并且应将参数命名为 Module,并将值设置为 "CimCmdlets"。

  • 脚本:在脚本开头,您需要指定参数的类型。(可选)您也可以强制使用参数,以强制脚本始终使用调用者设置的参数进行调用。

例如,以下脚本支持使用两个参数, 其中一个参数类型为字符串,另一个参数类型为整数:

Param(
  [Parameter(Mandatory=$true)]
  [string]$Name,
  [int]$Age
)
Param(
  [Parameter(Mandatory=$true)]
  [string]$Name,
  [int]$Age
)

然后,通过在参数名称前面添加 $,即可在脚本中引用这些参数。

  • Input - A collection of PSObjects that are passed to the writer of the pipeline used to execute the command. Can be the output of another Invoke PowerShell activity. You can reference piped input in a script by using $input.
    备注:

    此变量由 PowerShell 隐式创建。定义名为input变量或参数可能会生成错误或导致冲突。建议为管道保留input一词。

选项​

  • 是脚本 - 指定命令文本是脚本还是直接命令。管道、变量和参数可与单个命令或脚本一起使用。
  • 执行模式 - 选择要用于执行所提供命令或脚本的 PowerShell 版本。这仅适用于 Windows 项目,Windows 旧版项目目标 Windows PowerShell 5.1(32 位)版本。 可选择以下选项:
    • PowerShell 7.2.15(64 位) - 使用基于.NET6 PowerShell Core Shell。在此版本中,PowerShell 托管在.NET 6 Runtime 中。使用的任何数据都可以通过该活动直接访问,并且可以导入到工作流中。
    • PowerShell 5.1(64 位) - 使用 64 位 Windows PowerShell 可执行文件。在此版本中,PowerShell 与 Windows 捆绑在一起,默认情况下位于C:\Windows\System32\WindowsPowerShell\v1.0\中。在此执行模式下,PowerShell 使用预装的 Shell 在计算机本地远程运行。.NET Remoting 引入了在不同 .NET 运行时之间序列化和反序列化信息的需求,因此无法重建的对象包含在PSObject或PSCustomObject中。
    • PowerShell 5.1(32 位) - 使用 32 位 Windows PowerShell 可执行文件。在此版本中,PowerShell 与 Windows 捆绑在一起,默认情况下位于C:\Windows\SysWOW64\WindowsPowerShell\v1.0\或 )。在此执行模式下,PowerShell 使用预装的 Shell 在计算机本地远程运行。.NET Remoting 引入了在不同 .NET 运行时之间序列化和反序列化信息的需求,因为无法重建的此类对象包含在PSObject或PSCustomObject中。PSObject和PSCustomObjects保存有关原始对象整体结构的信息,可用于手动重建对象。
  • PowerShellVariables - A dictionary of named objects that represent variables used within the current session of the Invoke PowerShell activity. A PowerShell command or script can retrieve information from In and In/Out variables and can set Out variables. To reference variables in your script, use the variable identifier character $ to denote that the text after is a variable name. Example: $firstVariable.
    备注:

    变量名称不区分大小写。

  • 当前类型- 设置在输出中返回的对象类型。

其他​

  • “私有”- 选中后将不再以“Verbose”级别记录变量和参数的值。

输出​

  • Output - A collection of objects of the type set in Current type, returned by the execution of the command. Can be used to pipe several Invoke PowerShell activities.
  • 描述​
  • 项目兼容性​
  • 配置​
  • 属性面板​
  • 常见​
  • 输入​
  • 选项​
  • 其他​
  • 输出​

此页面有帮助吗?

连接

需要帮助? 支持

想要了解详细内容? UiPath Academy

有问题? UiPath 论坛

保持更新