c# - 如何使用 System.Management.Automation.Runspaces.Command 从 powershell 文件运行命令
问题描述
我正在尝试使用System.Management.Automation.Runspaces.Pipeline
类从 powershell 文件运行命令。
当我将脚本直接作为字符串传递时它可以工作
Runspace runspace = RunspaceFactory.CreateRunspace();
runspace.Open();
Pipeline pipeline = runspace.CreatePipeline();
pipeline.Commands.AddScript(script);
List<PSObject> results = pipeline.Invoke().ToArray().ToList();
但我不知道如何从 powershell 文件运行命令。基本上我想从powershell文件运行脚本
我也尝试检查System.Management.Automation.Runspaces.Command
类的方法,但在那里找不到任何有用的东西。
有人可以帮忙吗?
解决方案
推荐阅读
- python-3.x - 在服务器上选择第二个 GPU
- typescript - TypeScript - 查找类类型
- discord.py - 为什么要删除这个错误?类型错误:on_message() 缺少 1 个必需的位置参数:“消息”
- python - 在 Python 3 中从变量中减去值时遇到问题
- css - 有没有办法在没有 Javascript 的情况下将标签的属性分配为 Sass/Css 中的变量?
- r - 通过马尔可夫链模拟步骤
- google-apps-script - 检查文件名是否存在并在 Google Script 中更新文件
- javascript - AWS SQS FIFO短轮询receiveMessage不返回任何消息
- azure-devops - Azure DevOps 将存储库重新连接到现有文件夹
- python - 为什么这个程序不异步运行?