gpt4 book ai didi

PowerShell 说 "execution of scripts is disabled on this system."

转载 作者:行者123 更新时间:2023-12-03 03:51:17 25 4
gpt4 key购买 nike

我正在尝试运行一个从 cmd.exe 调用 PowerShell 脚本的 cmd 文件,但收到此错误:

Management_Install.ps1 cannot be loaded because the execution of scripts is disabled on this system.

我运行了这个命令:

Set-ExecutionPolicy -ExecutionPolicy Unrestricted

当我从 PowerShell 运行 Get-ExecutionPolicy 时,它返回 Unrestricted

Get-ExecutionPolicy

输出:

Unrestricted
<小时/>

cd "C:\Projects\Microsoft.Practices.ESB\Source\Samples\Management Portal\Install\Scripts"powershell .\Management_Install.ps1 1

WARNING: Running x86 PowerShell...

File C:\Projects\Microsoft.Practices.ESB\Source\Samples\Management Portal\Install\Scripts\Management_Install.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see "get-help about_signing" for more details.

At line:1 char:25

  • .\Management_Install.ps1 <<<< 1

    • CategoryInfo : NotSpecified: (:) [], PSSecurityException

    • FullyQualifiedErrorId : RuntimeException

C:\Projects\Microsoft.Practices.ESB\Source\Samples\Management Portal\Install\Scripts> PAUSE

Press any key to continue . . .

<小时/>

系统是Windows Server 2008 R2。

我做错了什么?

最佳答案

如果您使用Windows Server 2008 R2 还有一个 x64x86 版本的 PowerShell,这两个版本都必须设置其执行策略。您是否在两台主机上都设置了执行策略?

作为管理员,您可以通过在 PowerShell 窗口中输入以下内容来设置执行策略:

Set-ExecutionPolicy RemoteSigned

有关详细信息,请参阅 Using the Set-ExecutionPolicy Cmdlet

完成后,您可以使用以下方法将策略设置回默认值:

Set-ExecutionPolicy Restricted

您可能会看到一个错误:

Access to the registry key
'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell' is denied.
To change the execution policy for the default (LocalMachine) scope,
start Windows PowerShell with the "Run as administrator" option.
To change the execution policy for the current user,
run "Set-ExecutionPolicy -Scope CurrentUser".

因此您可能需要像这样运行命令(如评论中所示):

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

关于PowerShell 说 "execution of scripts is disabled on this system.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4037939/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com