绕过与不受限制的执行策略

Bypass vs Unrestricted execution policies

题目中的documentation只提供了这个:

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.

在我看来,这两个似乎会接受任何脚本,但令我惊讶的是,事实并非如此。在某些情况下,绕过似乎会阻止执行。

那么,两者有什么区别呢?

根据评论,这些执行策略的行为应该没有特别的区别。但是,Bypass 旨在用于在 Powershell.exe 的单个 运行 期间临时更改执行策略时使用,而 Unrestricted 旨在用于如果您希望永久更改系统范围之一(MachinePolicy、UserPolicy、Process、CurrentUser、LocalMachine)的执行策略设置。

一些示例:

  1. 您所在的系统要将执行策略更改为永久不受限制,以便任何用户都可以 运行 任何 PowerShell 脚本而不会出现问题。你会 运行:

     Set-ExecutionPolicy Unrestricted
    
  2. 您所在的系统的执行策略会阻止您的脚本,但您希望通过 PowerShell 运行 它并在 运行 时忽略执行策略。你会 运行:

     powershell.exe .\yourscript.ps1 -executionpolicy bypass
    
  3. 您 运行 Powershell.exe 在执行策略阻止脚本执行的系统上,但您想更改此策略只是为了交互 powershell.exe 你所在的会话。你会 运行:

      Set-ExecutionPolicy Bypass -Scope Process
    

不同之处在于您在问题中给出的描述。 Unrestricted让你沉迷于所有电脑运行windows,只使用NTFS,只用保存ADS的浏览器下载东西的错觉。事实上,如果您将 windows 中的文件保存到服务器上未使用 NTFS 的 FAT 文件系统或网络共享,或者以其他方式下载它,例如使用 git,powershell 认为它是本地的无论它来自哪里都被创造出来。 Bypass 不检查任何这些,只检查 运行 的所有内容。 Unrestricted 应该警告您它认为可能危险但无法可靠地检查或确定的事情。使用任何你喜欢的东西。

PS> rm -path file.ps1 -stream zone.identifier
讨论...