Loading...

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

5 A+ A-

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


XAML 4666139187127090770

Enregistrer un commentaire

5 commentaires

Fred a dit…

better than AdminScriptEditor ?

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

(need to be registered to download the tool)

Damien Van Robaeys a dit…

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.

Diagg a dit…

Dam is back avec un top billet !!!

Damien Van Robaeys a dit…

Merci Nico ☺☺

Anonyme a dit…

Nice post and good information. Thanks for sharing.
basic computer skills test
google adwords test

Accueil item

Award

Sponsors

Learn KQL in one month

You want to support me ?

Mes articles en français

Books in French


Stats