Powershell tool : How to quickly build a GUI with Powershell and XAML


In this post I will show you a quick way to create your own Powershell GUI.



I have rebuild a tool that I have already shared on my blog : Microsoft EXE extractor that I have done using "PrimalForms Community Edition".

In order to build the GUI i used Visual Studio 2012.


Some explanations about XAML and WPF


Why WPF and not Windows Forms
  • WPF is easy to create 
  • WPF design is better 
  • Possibility to reuse your old code
  • WPF is newer


More informations about WPF between Windows Forms


Build the GUI with Visual Studio
  • Select "New project"
  • Select "WPF applications"
Choose WPF applications
  • Select all controls you want in the side bar
Controls list
  • In the below part you can see the appropriate XAML code
XAML overview


How to link the XAML and the PS1 script ?
  • The first step is to load the XAML from your PS1, as below :


  • Remove the "x:Class" part from you XAML at the first line. 

<Window x:Class="application_name.MainWindow"


How to manipulate your controls ?

In order to manipulate your controls with the ps1 you have to name them in the xaml file.

You just have to add x:Name="button_test" to your control, as below :
  • <RadioButton x:Name="test" Content="test"/>
Then in the PS1 script, declare each control as below :
  • $button_test= $Form.findname("button_test")


Tested environments

  • Powershell v2
  • Powershell v3
  • Powershell v4
  • Windows 7 x86
  • Windows 7 x64



You can find in the below rar file the new Microsoft EXE exctrator tool. 
You can extract the content in order to get the XAML and PS1 files.
Download the Tool


4 Comments

  1. better than AdminScriptEditor ?

    http://www.itninja.com/community/admin-script-editor

    (need to be registered to download the tool)

    RépondreSupprimer
  2. I don't know it, but unless I'm wrong it seems to be a script editor like primalform, visualstudio ...

    So I guess you can also use XAML and Powershell with it.

    RépondreSupprimer