Bypass ExecutionPolicy included in PowerShell scripts

Eaven HUANG 2,131 Reputation points

Dear All,

Whenever I started a new PowerShell ISE window and tried to run some scripts, it prompts:
.ps1 cannot be loaded because running scripts is disabled on this system.

I know that we can set the Bypass command via PowerShell console and click Yes to all,
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass

But is there any way that we can include this kind of command into .ps1 file, maybe put it as the first line, then we can run the script directly without having to set the ep every time?

Many thanks.

Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,427 questions
0 comments No comments
{count} votes

Accepted answer
  1. Ian Xue (Shanghai Wicresoft Co., Ltd.) 32,076 Reputation points Microsoft Vendor


    Since the current execution policy is Restricted, no PowerShell script is allowed to run on your machine so you have to run that command in the console. But why not just run

    Set-ExecutionPolicy -ExecutionPolicy RemoteSigned  

    Is there any reason to set the scope to Process?

    Best Regards,
    Ian Xue


    If the Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

0 additional answers

Sort by: Most helpful