DougFinke

Untitled

Oct 25th, 2011
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.48 KB | None | 0 0
  1. using System.Management.Automation;
  2.  
  3. namespace PowerShellExt
  4. {
  5.     public static class Execution
  6.     {
  7.         public static void ExecutePS(this string script)
  8.         {
  9.             var result = PowerShell
  10.                 .Create()
  11.                 .AddScript(script)
  12.                 .AddCommand("Out-String")
  13.                 .Invoke();
  14.  
  15.             foreach (var item in result)
  16.             {
  17.                 System.Console.WriteLine(item);
  18.             }
  19.         }
  20.     }
  21. }
  22.  
Advertisement
Add Comment
Please, Sign In to add comment