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

我做错了什么?


当前回答

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

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

然后执行脚本。

然后恢复更改,如:

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

其他回答

设置执行策略是特定于环境的。如果您试图从正在运行的x86 ISE执行脚本,则必须使用x86 PowerShell设置执行策略。同样,如果您正在运行64位ISE,则必须使用64位PowerShell设置策略。

如果您在这里是因为使用Ruby或Chef运行它并使用“”系统执行,请执行如下操作:

`powershell.exe -ExecutionPolicy Unrestricted -command [Environment]::GetFolderPath(\'mydocuments\')`

该命令用于获取“MyDocuments”文件夹。

-ExecutionPolicy Unrestricted就是这样。

我希望这对其他人有帮助。

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

Set-ExecutionPolicy -ExecutionPolicy Remotesigned 

您可以使用特殊方式绕过它:

Get-Content "PS1scriptfullpath.ps1" | Powershell -NoProfile -

它将PowerShell脚本的内容通过管道传输到PowerShell.exe,并绕过执行策略执行它。

打开运行命令/控制台(Win+R)类型:gpedit。msc(组策略编辑器)浏览到本地计算机策略->计算机配置->管理模板->Windows组件->Windows Powershell。启用“启用脚本执行”根据需要设置策略。我将我的设置为“允许所有脚本”。

现在运行运行命令,无论您使用什么。。相信这一点,应用程序将运行。。享受:)