PowerShell 说“在此系统上禁止执行脚本". [英] PowerShell says "execution of scripts is disabled on this system."

查看:84
本文介绍了PowerShell 说“在此系统上禁止执行脚本".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

<块引用>

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

我运行了这个命令:

Set-ExecutionPolicy -ExecutionPolicy Unrestricted

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

PS C:\Users\Administrator\>获取执行策略无限制


<块引用>

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

警告:正在运行 x86 PowerShell...

文件 C:\Projects\Microsoft.Practices.ESB\Source\Samples\Management Portal\Install\Scripts\Management_Install.ps1 无法加载,因为在此系统上禁用了脚本的执行.请参阅get-help about_signing"了解更多详情.

在第 1 行字符:25

  • .\Management_Install.ps1 <<<<1

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

    • FullyQualifiedErrorId:运行时异常

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

按任意键继续...


系统为Windows Server 2008R2.

我做错了什么?

解决方案

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

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

Set-ExecutionPolicy RemoteSigned

有关详细信息,请参阅使用 Set-ExecutionPolicy Cmdlet.

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

Set-ExecutionPolicy 受限

您可能会看到一个错误:

访问注册表项'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell' 被拒绝.要更改默认 (LocalMachine) 范围的执行策略,使用以管理员身份运行"启动 Windows PowerShell选项.要更改当前用户的执行策略,运行Set-ExecutionPolicy -Scope CurrentUser".

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

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

I am trying to run a cmd file that calls a PowerShell script from cmd.exe, but I am getting this error:

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

I ran this command:

Set-ExecutionPolicy -ExecutionPolicy Unrestricted

When I run Get-ExecutionPolicy from PowerShell, it returns Unrestricted.

PS C:\Users\Administrator\> Get-ExecutionPolicy
Unrestricted


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 . . .


The system is Windows Server 2008R2.

What am I doing wrong?

解决方案

If you're using Windows Server 2008 R2 then there is an x64 and x86 version of PowerShell both of which have to have their execution policies set. Did you set the execution policy on both hosts?

As an Administrator, you can set the execution policy by typing this into your PowerShell window:

Set-ExecutionPolicy RemoteSigned

For more information, see Using the Set-ExecutionPolicy Cmdlet.

When you are done, you can set the policy back to its default value with:

Set-ExecutionPolicy Restricted

You may see an error:

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".

So you may need to run the command like this (as seen in comments):

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

这篇关于PowerShell 说“在此系统上禁止执行脚本".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆