Visual Studio Code 未签名 Powershell 脚本

Rya*_*ard 8 powershell visual-studio-code

我开始使用 Visual Studio Code 进行 Powershell 脚本编写。我想关闭对未签名代码的检查,但不知道如何执行此操作。我也没有在论坛上找到任何东西。

小智 14

PowerShell 的默认设置有助于防止恶意脚本运行。默认情况下,您应该/可以在 VSCode 集成终端上运行脚本。

要更改 PowerShell 安全设置,请使用管理员权限打开 PowerShell 并运行以下命令:

Get-ExecutionPolicy -List
Run Code Online (Sandbox Code Playgroud)

您应该得到如下响应:

        Scope ExecutionPolicy
    ----- ---------------
MachinePolicy       Undefined
   UserPolicy       Undefined
      Process       Undefined
  CurrentUser       RemoteSigned  
 LocalMachine       AllSigned
Run Code Online (Sandbox Code Playgroud)

CurrentUser 也可能未定义,因为您无法在 VSCode 终端上运行脚本。

要更改它,请运行以下命令:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Run Code Online (Sandbox Code Playgroud)

重新打开 VSCode 终端,它现在应该可以工作了。

如果您想了解更多详细信息,可以在此处找到完整的文档: https: //learn.microsoft.com/es-es/powershell/module/microsoft.powershell.core/about/about_execution_policies ?view=powershell-7


use*_*107 12

您可以通过向 powershell.exe 命令添加参数来调整策略。为此,打开设置 json 文件。然后添加以下行:

    "terminal.integrated.shellArgs.windows": "-ExecutionPolicy ByPass",
Run Code Online (Sandbox Code Playgroud)

  • 最新版本的 VS Code 似乎已弃用此设置。 (7认同)

小智 9

我通过将策略设置为:

Set-ExecutionPolicy –ExecutionPolicy RemoteSigned
Run Code Online (Sandbox Code Playgroud)

到以管理员身份运行的 Visual code 集成环境。

下面的博客清楚地列出了解决它的步骤:

http://donovanbrown.com/post/Using-PowerShell-in-VS-Code


Yet*_*ser 2

您可以使用该命令Set-ExecutionPolicy来更改系统的执行策略。您需要在管理会话中执行此操作。help Set-ExecutionPolicy您可以通过使用PowerShell 提示符下的命令找到适当的语法。

您还可以在线查找命令参考,例如SS64Technet

Stack Overflow 上还有一个非常明显的问答,其中包含相同的信息。