Execute a powershell script from c#


/ Published in: C#
Save to your folder(s)



Copy this code and paste it in your HTML
  1. string cmdArg = ".\script.ps1 -foo bar" �  �  �  �  �  � 
  2. Collection<PSObject> psresults;
  3. using (Pipeline pipeline = _runspace.CreatePipeline())
  4. �  �  �  �  �  �  {
  5. �  �  �  �  �  �  �  �  pipeline.Commands.AddScript(cmdArg);
  6. �  �  �  �  �  �  �  �  pipeline.Commands[0].MergeMyResults(PipelineResultTypes.Error, PipelineResultTypes.Output);
  7. �  �  �  �  �  �  �  �  psresults = pipeline.Invoke();
  8. �  �  �  �  �  �  }
  9. return psresults;

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.