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


Share this

Related Posts

Previous
Next Post »

4 commentaires

commentaires
21 octobre 2015 à 20:00 delete

better than AdminScriptEditor ?

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

(need to be registered to download the tool)

Reply
avatar
22 octobre 2015 à 10:18 delete

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.

Reply
avatar
22 octobre 2015 à 22:17 delete

Dam is back avec un top billet !!!

Reply
avatar