PowerShell 说“在这个系统上禁用了脚本的执行”

问题描述

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

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

Set-ExecutionPolicy RemoteSigned

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

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

解决方法

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

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

我运行了这个命令:

Set-ExecutionPolicy -ExecutionPolicy Unrestricted

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

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

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

按任意键继续 。. .


系统为 Windows Server 2008R2。

我究竟做错了什么?

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...