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) { //execute powershell cmdlets or scripts using command arguments as process ProcessStartInfo processInfo = new ProcessStartInfo(); processInfo.FileName = @"powershell.exe"; //execute powershell script using script file //processInfo.Arguments = @"& {c:\temp\Get-EventLog.ps1}"; //execute powershell command processInfo.Arguments = @"& {Get-EventLog -LogName Application -Newest 10 -EntryType Information | Select EntryType, Message}"; processInfo.RedirectStandardError = true; processInfo.RedirectStandardOutput = true; processInfo.UseShellExecute = false; processInfo.CreateNoWindow = true; //start powershell process using process start info Process process = new Process(); process.StartInfo = processInfo; process.Start(); Console.WriteLine("Output - {0}", process.StandardOutput.ReadToEnd()); Console.WriteLine("Errors - {0}", process.StandardError.ReadToEnd()); Console.Read(); } } }