PowerShell GUI

PowerShell scriptign can be used to create graphical user interfaces quite easily.

No need to import specific modules or to purchase any external software, PowerShell works with WinForms out of the box.

.

1. GUI Step By Step

1.1 Interface Definition

To create a GUI using PowerShell, the first thing to do is to define properly the interface.

.

Then, you can specify to hide the PowerShell Console in background.

.

.

1.2 Main Form Definition

Define the main form (location, size, title…)

.

.

1.3 Content

Now that the interface is defined and created, it’s time to put the content.

A lot of controls are available, each one with its own properties and specificities.

For example, we can add a Groupbox with a short description of what the script does by following these steps:

  • Creation of the Groupbox
  • Creation of the Label (which contains the text)
  • Assign the Label to the Groupbox
  • Assign the Groupbox to the Main Form

.

And then we can add 2 buttons, allowing respectively to create a folder and to remove it:

  • Creation of a Groupbox (just for the cosmetic J)
  • Creation of the first Button (Create Folder)
  • Creation of the second Button (Remove Folder)
  • Assign the Buttons to the Groupbox
  • Assign the Groupbox to the Main Form

The “Add-Click” property allows to call a function when the button is clicked.

.

.

1.4 Functions

It’s now time to add the functions used to define the behavior of the script.

In our example, we have to add the functions CreateFolder and RemoveFolder which allows respectively to create and remove a folder by clicking the according button previously defined.

.

Don’t forget to create the Main function allowing to display the interface.

.

.

1.5 Call the Main Function

The last step is to call the main function to display the interface:

.

.

2. Controls

Here is a list of useful which can be used.

.

GroupBox

.

Panel

.

Label

.

Checkbox

.

Radio Button

.

ComboBox

.

TextBox

.

PictureBox

.

Button

.

DateTimePicker

.

.

3. Demo

.