我正在尝试运行从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,我应该使用cmd提示符

其他回答

首先,您需要打开PowerShell窗口并运行此命令。

set ExecutionPolicy RemoteSigned-作用域CurrentUser

然后它会要求您确认。键入Y并按Enter键。

运行此命令时,可以看到系统已将当前用户的所有策略设置为远程。完成此过程需要几秒钟。

图像如下所示:

检查执行策略是否已设置。类型:

获取执行策略

如果设置了它,输出将如下所示:

在我的情况下,发生这种情况是因为我使用PowerShell,我应该使用cmd提示符

在PowerShell ISE编辑器中,我发现运行以下第一行允许的脚本。

Set-ExecutionPolicy RemoteSigned -Scope Process

运行Set ExecutionPolicy RemoteSigned命令

以管理员身份打开Powershell控制台,然后设置执行策略

Set-ExecutionPolicy -ExecutionPolicy Remotesigned