【发布时间】:2018-04-11 22:29:27
【问题描述】:
我开始使用 Visual Studio Code 编写 Powershell 脚本。我想关闭对未签名代码的检查,但不知道如何执行此操作。我也没有在论坛里找到任何东西。
【问题讨论】:
-
从 PowerShell 提示符运行命令:
help about_Execution_Policies。
标签: powershell visual-studio-code
我开始使用 Visual Studio Code 编写 Powershell 脚本。我想关闭对未签名代码的检查,但不知道如何执行此操作。我也没有在论坛里找到任何东西。
【问题讨论】:
help about_Execution_Policies。
标签: powershell visual-studio-code
我通过将策略设置为来解决:
Set-ExecutionPolicy –ExecutionPolicy RemoteSigned
到以管理员身份运行的可视化代码集成环境。
下面的博客清楚地列出了解决它的步骤:
【讨论】:
您可以通过向 powershell.exe 命令添加参数来调整策略。 为此,打开设置 json 文件。然后添加以下行:
"terminal.integrated.shellArgs.windows": "-ExecutionPolicy ByPass",
【讨论】:
PowerShell 的默认设置有助于防止运行恶意脚本。默认情况下,您应该/可以在 VSCode 集成终端上运行脚本。
要更改 PowerShell 安全设置,请以管理员权限打开 PowerShell 并运行命令:
Get-ExecutionPolicy -List
你应该得到这样的回应:
Scope ExecutionPolicy
----- ---------------
MachinePolicy Undefined
UserPolicy Undefined
Process Undefined
CurrentUser RemoteSigned
LocalMachine AllSigned
CurrentUser 也可能未定义,因为您无法在 VSCode 终端上运行脚本。
要更改它,请运行以下命令:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
重新打开 VSCode 终端,它现在应该可以工作了。
如果您想了解更多详细信息,可以在此处找到完整文档:https://docs.microsoft.com/es-es/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7
【讨论】:
【讨论】: