powershellexecutionpolicy

Bypass vs Unrestricted execution policies


The documentation on the topic only provides this:

Unrestricted. Loads all configuration files and runs all scripts. If you run an unsigned script that was downloaded from the Internet, you are prompted for permission before it runs.

Bypass. Nothing is blocked and there are no warnings or prompts.

To me it seems like the two would accept any scripts, but to my surprise it's not the case. Bypass seems to block execution in some cases.

So, what is the difference between the two ?


Solution

  • Per the comments, there should be no particular difference with how these execution policies behave (except those noted by @DennisSimpson in his answer, where on Windows use of "Unrestricted" may still result in a prompt if the file was detected as downloaded from the internet). Typically, Bypass is used when you are temporarily changing the execution policy during a single run of Powershell.exe, where as Unrestricted is used if you wish to permanently change the setting for the execution policy for one of the system scopes (MachinePolicy, UserPolicy, Process, CurrentUser, LocalMachine).

    Some examples:

    1. You are on a system where you want to change the execution policy to be permanently unrestricted so that any user could run any PowerShell script without issue. You would run:

       Set-ExecutionPolicy Unrestricted
      
    2. You are on a system where the execution policy blocks your script, but you want to run it via PowerShell and ignore the execution policy when run. You would run:

       powershell.exe .\yourscript.ps1 -executionpolicy bypass
      
    3. You run Powershell.exe on a system where the execution policy blocks the execution of scripts, but you want to change this policy just for the life of the interactive powershell.exe session that you're in. You would run:

        Set-ExecutionPolicy Bypass -Scope Process