Invoke PowerShell - File Cannot Be Loaded Because Running Scripts Is Disabled On This System

How to run PowerShell scripts with Studio 23.4?

Issue:

After upgrading to Studio / Robot 2023.4, running using "Invoke PowerShell" activity with a script will throw the following error,

File [path] cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at https://go.microsoft.com/fwlink/?LinkID=135170.

Initial Activity Configuration:


Root Cause: Windows projects execute internal PowerShell version that uses its own set of execution policies and not the one on the machine. And providing just the path to the script acts as trying to execute the script already, and that is blocked by those internal execution policies.


Resolution:

Approach #1:

  • Add the execution policy right before the script path, using a break line:

Or

Approach #2:

  • Use "Read Text File" and use its output for "Invoke PowerShell". Also enable "IsScript".