1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
using System; using System.Management.Automation; // Windows PowerShell namespace. namespace PowerSh { class PowerSh { static void Main(string[] args) { //Create a PowerShell object. PowerShell ps = PowerShell.Create(); //Add the command that you want to execute. ps.AddCommand("Get-Process"); //Add the command that you want to execute. ps.AddCommand("out-file"); //Add the argument ps.AddArgument("out.txt"); //Invoke the command. ps.Invoke(); } // End Main. } // End HostPs1. } |