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 |
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(); ps.AddCommand("Get-WmiObject"); ps.AddArgument("win32_physicalmemory"); ps.AddCommand("sort-object"); ps.AddArgument("Manufacturer"); // Call the PowerShell.Invoke() method to run the // commands of the pipeline in the default runspace. foreach (PSObject result in ps.Invoke()) { Console.WriteLine(result.Members["Manufacturer"].Value); } // End foreach. } // End Main. } // End HostPs1. } |