无法加载.ps1,因为此系统上禁用了脚本执行 [英] .ps1 cannot be loaded because the execution of scripts is disabled on this system

查看:107
本文介绍了无法加载.ps1,因为此系统上禁用了脚本执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行以下代码以从ASP.NET应用程序执行PowerShell代码:

I run this code to execute PowerShell code from an ASP.NET application:

System.Management.Automation.Runspaces.Runspace runspace = System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace();
runspace.Open();
System.Management.Automation.Runspaces.Pipeline pipeline = runspace.CreatePipeline();
pipeline.Commands.AddScript(@"\\servername\path");

pipeline.Commands.Add("Out-String");

Collection<PSObject> results = pipeline.Invoke();

runspace.Close();

但是我遇到一个错误:

.ps1无法加载,因为在以下位置禁用了脚本的执行: 这个系统.有关更多详细信息,请参见获得有关about_signing的帮助".

.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see "get-help about_signing" for more details.

从命令提示符或Windows(Windows窗体)应用程序运行相同的代码即可.

The same code runs fine from a command prompt or a windows (Windows Forms) application.

推荐答案

由于您需要以管理员身份运行PowerShell,并将其在客户端PC上设置为Unrestricted.您可以通过以下方式调用Invoke:

You need to run PowerShell as administrator and set it on the client PC to Unrestricted. You can do that by calling Invoke with:

Set-ExecutionPolicy Unrestricted

这篇关于无法加载.ps1,因为此系统上禁用了脚本执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆