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

查看:31
本文介绍了.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(@"\servernamepath");

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

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

runspace.Close();

但我收到一个错误:

.ps1 无法加载,因为脚本的执行在这个系统.有关详细信息,请参阅get-help 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 上设置为不受限制.你可以通过调用 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天全站免登陆