C#调用.ps1文件
C#调用.ps1文件,别人的项目拷到我的项目中,就报这个错误
“
Could not load file or assembly 'System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. 系统找不到指定的文件。”
求知道的给解答
private void RunPowershell(string filePath, string parameters) { RunspaceConfiguration runspaceConfiguration = RunspaceConfiguration.Create(); Runspace runspace = RunspaceFactory.CreateRunspace(runspaceConfiguration); runspace.Open(); RunspaceInvoke scriptInvoker = new RunspaceInvoke(runspace); Pipeline pipeline = runspace.CreatePipeline(); Command scriptCommand = new Command(filePath); Collection<CommandParameter> commandParameters = new Collection<CommandParameter>(); foreach (var parameter in parameters.Split(' ')) { CommandParameter commandParm = new CommandParameter(null, parameter); commandParameters.Add(commandParm); scriptCommand.Parameters.Add(commandParm); } (scriptCommand); Collection<PSObject> psObjects; psObjects = pipeline.Invoke(); } RunPowershell(@".\x.ps1", "");