PowerShell - ps1 script cannot be loaded because running scripts is disabled on this system

By xngo on January 5, 2020

I was trying to run a simple hello world powershell script in MS Windows and I got the following error message:

PS C:\xuan\to-del\ps> .\hello-world.ps1
.\hello-world.ps1 : File C:\xuan\to-del\ps\hello-world.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.
At line:1 char:1
+ .\hello-world.ps1
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo : SecurityError: (:) [], PSSecurityException
+ FullyQualifiedErrorId : UnauthorizedAccess

Solution

By default, powershell scripts will not in MS Windows due to security policy. To change the policy, do the followings:

  1. Open Run command or console ( Win + R ).
  2. Type in gpedit.msc to open the Local Group Policy Editor.
  3. Navigate to Local Computer Policy > Computer Configuration > Administrative Templates > Windows Components > Windows Powershell
  4. Enable Turn on Script Execution and set your desired Execution Policy. For simplicity, I set mine to Allow all scripts.
    MS Windows - Security Policy - Turn on Script Execution

About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.