Displaying Form For Output Only And Starting Without Button Click

I am trying to launch a PowerShell form after a process is finished by grabbing it’s exit code. I want this form to basically just display some information in a text box, prompt user, etc. WITHOUT having the user click on a button. Is this possible? After researching for hours, I have not been able to find an answer. I have used a similar form, but all script processes need to be included after “add_click” and then end the script with $form.ShowDialog() . Any ideas how I can get the script to start automatically after the form is loaded?

After hours of testing and researching, I am finally able to get it to work with “Add_Shown.” I just had to turn the script portion into a function and call that function via Add_Shown before loading the form. In this case, the function is called “Start-Script”:

$form.Add_Shown( { Start-Script } )

$drc = $form.ShowDialog()

How did you start the other process, via another script or from a form action?

If you are grabbing the exit code, then you have code running to look for it.

Just add code to open a message box, no real need to create a form just to display a message.

Since you are saying you want to do this when the form is loaded, then use the FormLoad, onload or Add_Loaded form event. There are lots of examples on how to do this all over the web. For Example:


Great, and good to know that you found the solution yourself and thanks for sharing it here.