powershell gui creator

How to Create a GUI for PowerShell Scripts?

One of the significant drawbacks of PowerShell scripts, when used by users (not sysadmins or programmers), is its command-line interface. The result of the scripts is displayed in the CLI window and it is not always convenient for the end user. However, Powershell is a powerful and modern automation tool for Windows that allows you to transparently use a variety of .NET Framework objects. For example, using the .NET API, you can easily create a simple graphical interface GUI for PowerShell scripts.

In this example, we’ll show you how to create a simple Windows GUI form using PowerShell and place on it various standard dialog elements. For example, our task is to write a simple GUI for a script that shows the last password change time for the Active Directory user. In this example, we use PowerShell 3.0+.

To use the .NET functionality to create forms, we use the class System.Windows.Forms. To load this class into a PowerShell session, you can use the following code:

Add-Type -assembly System.Windows.Forms

Now create the screen form (window):

$main_form = New-Object System.Windows.Forms.Form

Set the title and size of the window:

$main_form.Text ='GUI for my PoSh script'

$main_form.Width = 600

$main_form.Height = 400

To make the form automatically stretch, if the elements on the form are out of bounds, we use the AutoSize property.

$main_form.AutoSize = $true

Now you can display the form on the screen.


powershell gui scripts

As you can see, an empty form was displayed. To add various graphical dialog elements to it, before the last line ($main_form.ShowDialog()) add the code below.

Create a label element on the form:

$Label = New-Object System.Windows.Forms.Label

$Label.Text = "AD users"

$Label.Location  = New-Object System.Drawing.Point(0,10)

$Label.AutoSize = $true


Create a drop-down list and fill it with a list of accounts from the Active Directory domain that was obtained using the Get-ADuser cmdlet (from Active Directory for Windows PowerShell module):

$ComboBox = New-Object System.Windows.Forms.ComboBox

$ComboBox.Width = 300

$Users = get-aduser -filter * -Properties SamAccountName

Foreach ($User in $Users)




$ComboBox.Location  = New-Object System.Drawing.Point(60,10)


Add two more labels to the form. The second will show the time when the password was changed for the selected user:

$Label2 = New-Object System.Windows.Forms.Label

$Label2.Text = "Last Password Set:"

$Label2.Location  = New-Object System.Drawing.Point(0,40)

$Label2.AutoSize = $true


$Label3 = New-Object System.Windows.Forms.Label

$Label3.Text = ""

$Label3.Location  = New-Object System.Drawing.Point(110,40)

$Label3.AutoSize = $true


Now put the button on the form:

$Button = New-Object System.Windows.Forms.Button

$Button.Location = New-Object System.Drawing.Size(400,10)

$Button.Size = New-Object System.Drawing.Size(120,23)

$Button.Text = "Check"


Let’s add an event to this button when the user clicks on it. To convert the date from the TimeStamp format to the more convenient form, we use the function [datetime]::FromFileTime:



$Label3.Text =  [datetime]::FromFileTime((Get-ADUser -identity $ComboBox.selectedItem -Properties pwdLastSet).pwdLastSet).ToString('MM dd yy : hh ss')



Run the PowerShell script. As you can see, it fills the drop-down list with the names of the accounts from AD. If you select the user account and click the Check button, the form displays the time when the user’s last password was changed in Active Directory.

powershell gui examples

Similarly, you can create the following graphic elements on the form:

  • CheckBox
  • RadioButton
  • TextBox
  • ChekedListBox
  • GroupBox
  • ListBox
  • TabControl
  • ListView
  • TreeView
  • DateTimePicker
  • TrackBar
  • PictureBox
  • ProgressBar
  • HScrollBar
  • VScrollBar
  • ContextMenu
  • Menu

For more convenient creation of graphical elements for PowerShell forms, you can use the online editor to create a GUI form for PowerShell scripts: https://poshgui.com/Editor. With it, you can create a beautiful form with the necessary dialog elements.

powershell gui editor

And get the ready PoSh code for your GUI scripts.

powershell gui editor script

You may also like:

Time Configuration for a Virtualized Domain Contro... Today we will talk about some of the features of time configuration on a virtualized domain controllers. Typically, the time synchronization scheme in...
Removing Old and Unused Drivers from Driver Store ... Each time you install or update your device driver, Windows OS (since Vista) continues to store the old version of the driver in the system Driver Sto...
How to transfer FSMO Roles From a Failed Domain Co... In case domain controller, which owns FSMO (Flexible Single Master Operation) roles, is fail (virus attack, fatal software problems or catastrophic ha...
Installing WebDAV client on Windows Server 2016 WebDAV (Web Distributed Authoring and Versioning) is an extension of the HTTP/1.1 protocol. The WebDAV protocol allows to access files on the remote s...
Get-service: Checking the Status of Windows Servic... Using the Get-Service cmdlet you can get a list of all the services installed on the operating system, its status and startup type. This one and other...
  1. Posted by Antonio

Add Your Comment