Bypass ExecutionPolicy included in PowerShell scripts

Eaven HUANG 2,191 Reputation points
2021-07-14T03:38:46.393+00:00

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 for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

Accepted answer
  1. Anonymous
    2021-07-14T05:01:12.213+00:00

    Hi,

    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

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.