Powershell 操作被执行策略阻止
Powershell Operation Blocked By Execution Policy
运行:
Import-Module PowerShellGet
出现以下错误:
The file was skipped because of the following validation exception: File C:\program files\powershell\Modules\PackageManagement\PackageManagement.format.ps1xml cannot be loaded because its operation is blocked by software restriction policies, such as those created by using Group Policy..
运行:
Get-ExecutionPolicy -List
将 LocalMachine 显示为 RemoteSigned
关于使用正确的执行策略使代码 运行 有什么建议吗?
您的 PowerShell 执行策略可能会阻止 Import-Module
成功 运行ning。尝试 运行宁:
Set-ExecutionPolicy -ExecutionPolicy AllSigned -Scope Process
这将允许在当前 PowerShell 进程中 all signed scripts 到 运行。当您关闭 PowerShell 会话时,您将恢复到之前的执行策略。
如果模块仍然无法成功导入,您可以尝试:
Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process
请谨慎对待此设置,因为它将允许任何未签名的脚本 运行,包括潜在的恶意代码。如果您选择 ExecutionPolicy Bypass,请确保您信任正在安装的 script/modules。
您应该参阅此处的文档以了解更多详细信息:
https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.security/set-executionpolicy?view=powershell-7
运行:
Import-Module PowerShellGet
出现以下错误:
The file was skipped because of the following validation exception: File C:\program files\powershell\Modules\PackageManagement\PackageManagement.format.ps1xml cannot be loaded because its operation is blocked by software restriction policies, such as those created by using Group Policy..
运行:
Get-ExecutionPolicy -List
将 LocalMachine 显示为 RemoteSigned
关于使用正确的执行策略使代码 运行 有什么建议吗?
您的 PowerShell 执行策略可能会阻止 Import-Module
成功 运行ning。尝试 运行宁:
Set-ExecutionPolicy -ExecutionPolicy AllSigned -Scope Process
这将允许在当前 PowerShell 进程中 all signed scripts 到 运行。当您关闭 PowerShell 会话时,您将恢复到之前的执行策略。
如果模块仍然无法成功导入,您可以尝试:
Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process
请谨慎对待此设置,因为它将允许任何未签名的脚本 运行,包括潜在的恶意代码。如果您选择 ExecutionPolicy Bypass,请确保您信任正在安装的 script/modules。
您应该参阅此处的文档以了解更多详细信息: https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.security/set-executionpolicy?view=powershell-7