我正在尝试运行从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。

我做错了什么?


当前回答

以管理员身份打开PowerShell。运行以下命令

设置ExecutionPolicy RemoteSigned

询问时键入Y!

其他回答

打开Windows PowerShell命令窗口并运行以下查询以更改ExecutionPolicy:

设置ExecutionPolicy-ExecutionPolicy RemoteSigned-作用域CurrentUser

如果要求确认更改,请按Y键并按Enter键。

在脚本之前运行此命令也可以解决问题:

Set-ExecutionPolicy Unrestricted

在Windows 7中:

转到“开始”菜单并搜索“Windows PowerShell ISE”。

右键单击x86版本并选择“以管理员身份运行”。

在顶部,粘贴SetExecutionPolicy RemoteSigned;运行脚本。选择“是”。

对64位版本的Powershell ISE(非x86版本)也重复这些步骤。

我只是在澄清Chad Miller暗示的步骤。谢谢Chad!

以管理员身份打开PowerShell窗口。这会奏效的。

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

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

然后执行脚本。

然后恢复更改,如:

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