Encountering this error? It’s caused by restrictive execution policies that block scripts for security reasons. This guide explains the issue and provides actionable solutions.
PowerShell restricts script execution by default. Running a script like my example cdk.ps1
may trigger the following error message:
Script.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

This happens due to PowerShell’s default security settings, which restrict script execution to prevent unauthorized or malicious scripts from running.
Why Does This Happen?
By default, PowerShell applies an Execution Policy that controls how scripts are executed. These policies include:
– Restricted: No scripts are allowed to run (default setting).
– AllSigned: Only scripts signed by a trusted publisher can run.
– RemoteSigned: Local scripts can run, but downloaded scripts need to be signed.
– Unrestricted: All scripts can run without restrictions (not recommended).
The Fix: Change Your Execution Policy
To allow PowerShell scripts to run on your system, you need to change the execution policy. Follow these steps:
Step 1: Open PowerShell as Administrator
Step 2: Check Your Current Execution Policy
# Check current execution policy status Get-ExecutionPolicy -List

Step 3: Modify the Execution Policy
To allow local scripts and signed remote scripts to run, execute the following command:
# Set local execution policy to remote signed Set-ExecutionPolicy -Scope LocalMachine -ExecutionPolicy RemoteSigned

Alternatively, if you need a temporary solution that resets after closing PowerShell, run:
# Set local execution policy for current session Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass

Step 4: Confirm the Change
Run the following command to verify your new execution policy:
# Check current execution policy status Get-ExecutionPolicy -List
If the policy is now set to RemoteSigned, you should be able to run your script without issues.
Important Considerations
Security First:
Avoid setting your execution policy to Unrestricted
, as it allows all scripts to run, which can be a security risk.
For One-Time Script Execution:
Use Bypass
at the process level to avoid permanently changing security settings.
If Running on a Corporate System:
Your execution policy may be managed by an IT administrator. In such cases, contact your IT team for assistance.
Leave a Reply