Automation Action – Execute PowerShell | ThinkAutomation
Automation Action: Execute PowerShell
Execute PowerShell commands and assign the results to a variable.
In the PowerShell Command or Script you can either specify the command and it’s parameters or you can specify the command only and then provide parameter names, values & types in the Parameters Grid.
Example – Single Command With Parameters
To get the current Windows version. Set the PowerShell Command to Get-ItemProperty and add parameters:
| Parameter Name | Value | Type |
|---|---|---|
| Path | HKLM:SOFTWAREMicrosoftWindows NTCurrentVersion | String |
| Name | ReleaseId | String |
You can use %variable% replacements for parameter values (or part of).
If you need to pass multiple values to a single parameter, you need to send through a special ThinkAutomation array type. To do this, prefix your parameter value with the word ARRAY: followed by comma-separated values.
This will return:
ReleaseId : 2009 PSPath : Microsoft.PowerShell.CoreRegistry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersion PSParentPath : Microsoft.PowerShell.CoreRegistry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NT PSChildName : CurrentVersion PSDrive : HKLM PSProvider : Microsoft.PowerShell.CoreRegistry
Example – Command
You can also execute a PowerShell command/script. Set the Command to:
(Get-ItemProperty -Path "HKLM:SOFTWAREMicrosoftWindows NTCurrentVersion" -Name ReleaseId).ReleaseId
You can use %variable% replacements inside the Command, eg:
(Get-ItemProperty -Path "%RegKey%" -Name ReleaseId).ReleaseId
Nothing should be specified in the Parameters grid.
The above will return 2009.
Remember to enclose string parameters in quotes.
Running PowerShell Commands and Scripts
PowerShell is widely used to automate administrative tasks, interact with Windows services, query remote systems and integrate with third-party applications. The Execute PowerShell action allows ThinkAutomation to run PowerShell commands and scripts as part of larger automated workflows, with the output available for use by subsequent actions.
Some PowerShell commands complete almost instantly, while others may take longer to process large datasets, communicate with remote servers or wait for responses from external systems. ThinkAutomation includes configurable timeout controls to ensure long-running or stalled scripts do not prevent other automations from continuing.
Wait Max (Seconds)
Specify the maximum number of seconds ThinkAutomation should wait for a PowerShell command or script to complete. If execution exceeds this limit, the action raises an error and the automation can continue according to your configured error handling. This helps prevent unresponsive or poorly performing scripts from delaying or blocking automated workflows.
Assign To
Select the variable that you want the Response to be assigned to. The entire PowerShell command response will be assigned to the field/variable.
Testing
You can use the Test button to test the Command/Script. The response will be displayed and also copied to the clipboard.
External Modules
If your PowerShell command or script uses external modules/cmdlets you need to enter the module names in the Import Module Names entry. Separate multiple modules with commas. You can use the module name or path.
In order to be able to run the PowerShell script you need to set an appropriate PowerShell Execution Policy. For guidance on this from Microsoft, see: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-6