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:
- Open Run command or console ( Win + R ).
- Type in gpedit.msc to open the Local Group Policy Editor.
- Navigate to Local Computer Policy > Computer Configuration > Administrative Templates > Windows Components > Windows Powershell
- Enable Turn on Script Execution and set your desired Execution Policy. For simplicity, I set mine to Allow all scripts.