Try   HackMD

Powershell script (.ps1) are not runnable

Author: Junner
Date: 2/26/2025

When try to run PS script (.ps1), terminal came out an error:

.\*ps1 : File D:\Junner\setup_env.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
+ .\*ps1
+ ~~~~~~
    + CategoryInfo          : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess

Go open a PowerShell with administrator permission.
win+R > type powershell > hold ctrl+shift then enter

Open the permission for running PS script:

Set-ExecutionPolicy RemoteSigned -Force

And you can run your script.

After excuting, remember to turn this permission off.

Set-ExecutionPolicy Restricted -Force

Another way to open permission for certain file is:

powershell -ExecutionPolicy Bypass -File .\setup_env.ps1 

And this is just for temporary when using this prompt. After turning off the prompt, permission no longer exists.