PowerShell: Graphic User Interface

This is just for fun – I built a Toolbox for myself which includes some useful PowerShell scripts I wrote before. It looks simple but very handy, just a simple click on the script name and it will run.


An example, I am checking the hosts info in the DHCP server.


# my_toolbox.ps1 source codes

[void] [System.Reflection.Assembly]::LoadWithPartialName(“System.Drawing”)
[void] [System.Reflection.Assembly]::LoadWithPartialName(“System.Windows.Forms”)

# Add a new form
$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = “My Toolbox”
$objForm.Size = New-Object System.Drawing.Size(300,250)
$objForm.StartPosition = “CenterScreen”

# Add a new close button
$CloseButton = New-Object System.Windows.Forms.Button
$CloseButton.Location = New-Object System.Drawing.Size(110,180)
$CloseButton.Size = New-Object System.Drawing.Size(75,23)
$CloseButton.Text = “Close”

# Add a new label
$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size(10,15)
$objLabel.Size = New-Object System.Drawing.Size(280,20)
$objLabel.Text = “Please single click the tool to run:”

# Add a new listbox
$objCmdletsListbox = New-Object System.Windows.Forms.Listbox
$objCmdletsListbox.Location = New-Object System.Drawing.Size(30,40)
$objCmdletsListbox.Size = New-Object System.Drawing.Size(220,40)

# Add all scripts’ name in C:\Scripts\mytools.txt, and copy all scripts and associated files into C:\Scripts\
$items = Get-Content “C:\Scripts\mytools.txt”

# Add scripts into the listbox
foreach ($item in $items)
    [void] $objCmdletsListbox.Items.Add($item)

$objCmdletsListbox.Height = 120

# Defind the single click action
    $tool = $objCmdletsListbox.SelectedItem
    Write-Host $tool
    $result = Invoke-Expression C:\Scripts\$tool

$objForm.Topmost = $True

[void] $objForm.ShowDialog()



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s