1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
using System; using System.Management.Automation; // Windows PowerShell namespace. namespace HostPS1 { class HostPS1 { static void Main(string[] args) { // Call the PowerShell.Create() method to create an // empty pipeline. PowerShell ps = PowerShell.Create(); // Call the PowerShell.AddCommand(string) method. ps.AddCommand("Get-DnsClientCache"); Console.WriteLine("Entry Data"); Console.WriteLine("----------------------------"); // Call the PowerShell.Invoke() method to run the // commands of the pipeline in the default runspace. foreach (PSObject result in ps.Invoke()) { Console.WriteLine("{0,-24}{1}", result.Members["Entry"].Value, result.Members["Data"].Value); } // End foreach. } // End Main. } // End HostPs1. } |