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 33 34 35 36 |
$CodigoC = @" using System; using System.Management.Automation; // Windows PowerShell namespace. namespace HostPS1 { public class HostPS1 { public static void Main() { // 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. } "@ Add-Type -TypeDefinition $CodigoC -ErrorAction SilentlyContinue [HostPS1.HostPS1]::Main() |