I am running some PowerShell scripts in C# using the System.Management.Automation namespace. This works perfectly, except when I invoke the script, I very briefly see a command window flash onto the screen and then disappear. This behavior is not acceptable in my application.
I can avoid this behavior by launching a new Process and setting CreateNoWindow=true, however I would really prefer to use the managed PowerShell library. How can I do this in a non-interactive way that does't flash on the screen?
An example of some PowerShell that causes the window flash:
using (PowerShell ps = PowerShell.Create())
{
ps.AddCommand(@"Get-WindowsUpdateLog");
ps.AddParameter(@"-LogPath", @"C:\WindowsUpdate.Log");
var psOutput = ps.Invoke();
}