PowerShell "running scripts is disabled on this system" in CI
PowerShell refused to run a .ps1 file because the effective execution policy is Restricted or AllSigned. The script content is fine; the policy blocks loading it.
What this error means
Invoking a script file fails immediately with an UnauthorizedAccess error pointing at the about_Execution_Policies help topic. The same script may run when pasted inline, because inline commands are not gated the same way.
.\build.ps1 : File C:\actions-runner\_work\repo\build.ps1 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.
+ CategoryInfo : SecurityError: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccessCommon causes
Execution policy is Restricted or AllSigned
A Restricted policy blocks all script files; AllSigned blocks unsigned ones. Calling a .ps1 directly under either policy fails before the script runs.
Calling a script file instead of inline commands
CI runners often allow inline pwsh blocks but not arbitrary script files. Switching from inline run: to .\script.ps1 hits the policy that the inline form bypassed.
How to fix it
Set the policy for the current process only
Scope the relaxation to the running process so it does not change the machine and resets when the step ends.
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass -Force
.\build.ps1Run the script via the interpreter with a bypass flag
Bypass the policy for one invocation without changing any persisted setting.
pwsh -NoProfile -ExecutionPolicy Bypass -File ./build.ps1Use the workflow shell instead of a script file
- Put the commands inline under a pwsh: or powershell: step shell, which is not blocked by Restricted.
- Reserve .ps1 files for logic that must be reused, and call them with -ExecutionPolicy Bypass.
How to prevent it
- Set the process execution policy once at the top of the job, or invoke scripts via pwsh -ExecutionPolicy Bypass -File so the policy never blocks a run.