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

我做错了什么?


当前回答

删除C:\Users[your user]\AppData\Roaming\npm中的ng.ps1文件。

然后删除C:\Users\USER\AppData\Roaming中的npm缓存文件。

其他回答

要解决此问题,我们必须设置执行策略,以便PowerShell脚本在特定计算机上运行。以下是方法:

通过选择“以管理员身份运行”打开PowerShell控制台,并使用以下命令设置执行策略:set ExecutionPolicy RemoteSigned当提示继续时,键入“Y”

信用:https://www.sharepointdiary.com/2014/03/fix-for-powershell-script-cannot-be-loaded-because-running-scripts-is-disabled-on-this-system.html

对于下载的文件,右键单击→ 财产

然后单击取消阻止并单击确定。然后运行PowerShell脚本,它将不再抱怨无法运行。

以管理员身份打开PowerShell并运行Set ExecutionPolicy-Scope CurrentUser提供RemoteSigned并按Enter键运行集执行策略-作用域CurrentUser提供无限制并按Enter键

这也发生在我身上。对我来说,解决方案很简单。我没有意识到命令提示符中运行Nodemon的路径与安装包的位置不同。

所以它给了我你提到的同样的错误。

改变我的路径解决了这个问题。

在PowerShell 2.0中,执行策略默认设置为禁用。

从那时起,PowerShell团队做了很多改进,他们相信用户在运行脚本时不会破坏很多东西。因此,从PowerShell 4.0开始,默认情况下会启用它。

在您的情况下,从PowerShell控制台键入Set-ExecutionPolicy RemoteSigned,然后说yes。