有个文件ps1.ps1内容是:
get-windowsfeature web-server
在powershell命令行里能直接.\ps1.ps1运行出结果。
但在程序里:
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using System.Text;
namespace ConsoleApplication
{
class Program
{
static void Main(string[] args)
{
string result = RunScript(@"D:\ps1.ps1");//get-windowsfeature web-server
Console.Write(result);