我正在尝试运行从cmd.exe调用PowerShell脚本的cmd文件,但遇到以下错误:

无法加载Management_Install.ps1,因为在此系统上禁用了脚本的执行。

我运行了以下命令:

Set-ExecutionPolicy -ExecutionPolicy Unrestricted

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

Get-ExecutionPolicy

输出:

Unrestricted

cd“C:\Projects\Microsoft.Practices.ESB\Source\Samples\Management Portal\Install\Scripts”powershell。\管理安装.ps1 1警告:正在运行x86 PowerShell。。。无法加载文件C:\Projects\Microsoft.Practices.ESB\Source\Samples\Management Portal\Install\Scripts\Management_Install.ps1,因为在此系统上禁用了脚本的执行。有关详细信息,请参阅“get-helpabout_signing”。第1行字符:25.\Management_Install.ps1<<<1类别信息:未指定:(:)[],PSSecurityExceptionFullyQualifiedErrorId:运行时异常C: \Projects\Microsoft.Practices.ESB\Source\Samples\Management Portal\Install\Scripts>PAUSE按任意键继续。


系统为Windows Server 2008 R2。

我做错了什么?


当前回答

Win+R并键入复制粘贴命令,然后按OK:

powershell Set-ExecutionPolicy -Scope "CurrentUser" -ExecutionPolicy "RemoteSigned"

然后执行脚本。

然后恢复更改,如:

powershell Set-ExecutionPolicy -Scope "CurrentUser" -ExecutionPolicy "AllSigned"

其他回答

要解决此问题,我们必须设置执行策略,以便PowerShell脚本在特定计算机上运行。以下是方法:

通过选择“以管理员身份运行”打开PowerShell控制台,并使用以下命令设置执行策略:set ExecutionPolicy RemoteSigned当提示继续时,键入“Y”

信用:https://www.sharepointdiary.com/2014/03/fix-for-powershell-script-cannot-be-loaded-because-running-scripts-is-disabled-on-this-system.html

您也可以使用以下命令绕过此问题:

powershell Get-Content .\test.ps1 | Invoke-Expression

您还可以阅读Scott Sutherland的这篇文章,其中介绍了如果您没有管理员权限,绕过PowerShell Set ExecutionPolicy的15种不同方法:

绕过PowerShell执行策略的15种方法

“无法加载,因为在此系统上禁用了运行脚本”的解决方案:如何启用此系统错误时禁用运行脚本?要解决此问题,我们必须设置执行策略,以便PowerShell脚本在特定计算机上运行。此处允许执行PowerShell脚本:

通过选择“以管理员身份运行”打开PowerShell控制台,并使用以下命令获取执行策略:GetExecutionPolicy以获取应用的当前策略,例如“受限”。使用以下命令设置执行策略:Set ExecutionPolicy RemoteSigned当提示继续时,键入“Y”。

打开运行命令/控制台(Win+R)类型:gpedit。msc(组策略编辑器)浏览到本地计算机策略->计算机配置->管理模板->Windows组件->Windows Powershell。启用“启用脚本执行”根据需要设置策略。我将我的设置为“允许所有脚本”。

现在运行运行命令,无论您使用什么。。相信这一点,应用程序将运行。。享受:)

对于下载的文件,右键单击→ 财产

然后单击取消阻止并单击确定。然后运行PowerShell脚本,它将不再抱怨无法运行。