问题描述
如果您使用的是Windows Server 2008 R2,则有一个x64和x86版本的 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。
我究竟做错了什么?