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 PS1(PowerShell script) file using (PowerShell PowerShellInst = PowerShell.Create()) { string path = System.IO.Path.GetDirectoryName(@"C:\Temp\") + "\\Get-EventLog.ps1"; if (!string.IsNullOrEmpty(path)) PowerShellInst.AddScript(System.IO.File.ReadAllText(path)); Collection PSOutput = PowerShellInst.Invoke(); foreach (PSObject obj in PSOutput) { if (obj != null) { Console.Write(obj.Properties["EntryType"].Value.ToString() + " - "); Console.Write(obj.Properties["Source"].Value.ToString() + " - "); Console.WriteLine(obj.Properties["Message"].Value.ToString() + " - "); } } Console.WriteLine("Done"); Console.Read(); } } } }