private void PowershellHostControl1_InvocationStateChanged(object sender, System.Management.Automation.PSInvocationStateChangedEventArgs e) { switch (e.InvocationStateInfo.State) { case PSInvocationState.Running: break; case PSInvocationState.Failed: Environment.ExitCode = 1; Trace.WriteLine("InvocationStateChanged -> Failed", "Form"); ButtonN.Enabled = true; ButtonN.Text = "Finished"; ButtonN.Focus(); break; case PSInvocationState.Completed: case PSInvocationState.Disconnected: case PSInvocationState.Stopping: case PSInvocationState.NotStarted: case PSInvocationState.Stopped: default: Trace.WriteLine("InvocationStateChanged -> Finished Successfully!", "Form"); Environment.ExitCode = PowershellHostControl1.ExitCode; // Special Case, if the user passed the -silent switch, then just close the form foreach (var Arg in PowershellHostControl1.ParsedParameters) { if (Arg.Name != null) { if (Arg.Name.ToString().ToLower() == "verbose") { if ((bool)Arg.Value) { Trace.WriteLine("User passed in Verbose on the command line, do not auto-exit.", "Form"); ButtonN.Enabled = true; ButtonN.Text = "Finished"; ButtonN.Focus(); return; } } } } Trace.WriteLine("All done, close the form.", "Form"); this.Close(); break; } }
private void PowershellHostControl1_NextButtonRequest(object sender, EventArgs e) { Trace.WriteLine("The powershell script is waiting for user input.", "Form"); ButtonN.Enabled = true; ButtonN.Focus(); }