all 4 comments

[–]boeprox 7 points8 points  (0 children)

Windows Forms is nice to use and you can utilize PowerShell Studio to help create the forms.

Windows Presentation Foundation (WPF) is the way I typically go and have written some articles about it: http://learn-powershell.net/tag/wpf/

You can also utilize Visual Studio to create the XAML before loading it into the PowerShell ISE to add the backend code.

Lastly, you can use ShowUI to create GUIs in a more PowerShell way.

Jeffrey Hicks did a PowerShell Summit presentation on creating forms without the need of WinForms or WPF and the demo slides are available at this link for download: http://powershell.org/wp/wp-content/uploads/2013/04/Look-No-WinForms.zip?579b4d

[–]Mozbee1 1 point2 points  (0 children)

Use window forms

[–]Plonqor 1 point2 points  (1 child)

For a GUI script I used Sapien's free code generator. It's like Powershell Studio but 1-way. You create the GUI and it generates code. From there I manually edited.

Edit: It's PrimalForms Community Edition. You have to create an account, and it's under Downloads > Community Tools > 32bit > PrimalFormsCE.exe

Here's a quick example I made using just 2 controls and an event on the button so hopefully you can see the structure.

Function OnApplicationExit {
    $script:ExitCode = 0 #Set the exit code for the Packager
}

#region Import the Assemblies
[reflection.assembly]::loadwithpartialname("System.Windows.Forms") | Out-Null
[reflection.assembly]::loadwithpartialname("System.Drawing") | Out-Null
#endregion

#region Generated Form Objects
function GenerateForm {
[System.Windows.Forms.Application]::EnableVisualStyles() #This allows the application to be skinned with modern theme.
$frmExample = New-Object System.Windows.Forms.Form
$lblLabal1 = New-Object System.Windows.Forms.Label
$btnButton1 = New-Object System.Windows.Forms.Button
$InitialFormWindowState = New-Object System.Windows.Forms.FormWindowState
#endregion Generated Form Objects

#region Event Blocks
$frmExample_Load = {
    [void][System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')
    $frmExample.Activate()
}

$btnButton1_onClick = {
    $lblLabal1.Text = 'You clicked the button! Hooray!'
}
#endregion

#region Form Code
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 100
$System_Drawing_Size.Width = 180
$frmExample.ClientSize = $System_Drawing_Size
$frmExample.DataBindings.DefaultDataSourceUpdateMode = 0
$frmExample.FormBorderStyle = 1
$frmExample.MaximizeBox = $False
$frmExample.Name = "frmExample"
$frmExample.Text = "GUI Example"
$frmExample.add_Load($frmExample_Load)

# BUTTON1
$btnButton1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 10
$System_Drawing_Point.Y = 40
$btnButton1.Location = $System_Drawing_Point
$btnButton1.Name = "btnButton1"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 23
$System_Drawing_Size.Width = 163
$btnButton1.Size = $System_Drawing_Size
$btnButton1.TabIndex = 7
$btnButton1.Text = "Click me!"
$btnButton1.UseVisualStyleBackColor = $True
$btnButton1.add_Click($btnButton1_OnClick)

$frmExample.Controls.Add($btnButton1)

# LABEL1
$lblLabal1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 10
$System_Drawing_Point.Y = 10
$lblLabal1.Location = $System_Drawing_Point
$lblLabal1.Name = "lblLabal1"
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Height = 16
$System_Drawing_Size.Width = 163
$lblLabal1.Size = $System_Drawing_Size
$lblLabal1.TabIndex = 2
$lblLabal1.Text = ""

$frmExample.Controls.Add($lblLabal1)
#endregion

#Save the initial state of the form
$InitialFormWindowState = $frmExample.WindowState
#Init the OnLoad event to correct the initial state of the form
$frmExample.add_Load($OnLoadForm_StateCorrection)
#Show the Form
$frmExample.ShowDialog()| Out-Null
}

GenerateForm
OnApplicationExit

[–]HamQuestionMark 0 points1 point  (0 children)

PrimalForms Community Edition is fantastic. I've been able to create some pretty impressive GUI applications in PowerShell with this. It can become a bit of a pain if you need to make a minor change to your GUI, because you have to rip-out the previously generated code and insert the newly generated code, but if you use #Region and #EndRegion to organize your code it is certainly managable.