using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; using System.Linq; using System.Management.Automation; using System.Text; using System.Threading; using System.Threading.Tasks; namespace PowerShellScriptExecutor { class Program { static void Main(string[] args) { using (PowerShell PowerShellInst = PowerShell.Create()) { string criteria = "system*"; PowerShellInst.AddScript("Get-Service -DisplayName " + criteria); Collection PSOutput = PowerShellInst.Invoke(); foreach (PSObject obj in PSOutput) { if (obj != null) { Console.Write(obj.Properties["Status"].Value.ToString() + " - "); Console.WriteLine(obj.Properties["DisplayName"].Value.ToString()); } } Console.WriteLine("Done"); Console.Read(); } } } }