PowerShell Command

Runs a command written in the Windows PowerShell language.

Command availability: IBM RPA SaaS and IBM RPA on premises

Script syntax

IBM RPA's proprietary script language has a syntax similar to other programming languages. The script syntax defines the command's syntax in the script file. You can work with this syntax in IBM RPA Studio's Script mode.

powerShell [--handleerror(Boolean)] [--apartmentState(ApartmentState)] [--fromfile(Boolean)] --file(String) --script(String) (Boolean)=success (List<String>)=errors (List<String>)=warnings

Input parameters

The following table displays the list of input parameters available in this command. In the table, you can see the parameter name when working in IBM RPA Studio's Script mode and its Designer mode equivalent label.

Designer mode label Script mode name Required Accepted variable types Description
Handle Error handleerror Optional Boolean Enable it to ignore errors that happen during runtime. For more information, see Exception Handling.
"Thread" Type apartmentState Optional ApartmentState Forms of division of the process that must be used in the execution, being them STA 🡥 or MTA.
Execute from File fromfile Optional Boolean Enable it to run the script with the PowerShell commands contained in a file.
File file Required when Execute from File is enabled Text Specify the file that contains the PowerShell script.
Powershell Script script Required when Execute from File is not enabled Text PowerShell commands, known as cmdlets 🡥.

Output parameters

Designer mode label Script mode name Accepted variable types Description
Success success Boolean Returns True if the PowerShell script runs successfully. Otherwise, returns False.
Errors errors List<Text> Returns a list of errors resulting from running the PowerShell script.
Warnings warnings List<Text> Returns a list of warnings from running the PowerShell script.

Example

The "get-Process" command is executed to obtain the process that is running on the local computer, returning its execution success, errors and warnings, if any.

defVar --name success --type Boolean
defVar --name errorList --type List --innertype String
defVar --name waningsList --type List --innertype String
powerShell --apartmentState "STA" --script "Get-Process" success=success errorList=errors waningsList=warnings
logMessage --message "Success: ${success}\r\nError: ${errorList}\r\nWarnings: ${waningsList}" --type "Info"
// Result: True
// Error: []
// Warnings: []