I really like having a graphic output to my scripts. Just having a log file to read, a Status Box to come with “Success” or “Fail” and even better – be green or red 🙂
Even better – let’s never use HTA again !
As a GUI guy, the best option to build a GUI Application would be to use a development tool and do it properly, on C# or other programming language. But sometimes we need something a little more quick and dirty and lightweight, so this is exactly what I mean
This is just a Demo Application, which I built, to show you how to combine the power and simplicity of PowerShell and XAML, to create wonderful scripts with Graphic Interfaces

So, let’s see how to make it work…
First we’d need to install a XAML Editor. You can download the free version of Visual Studio Community from the below link
https://visualstudio.microsoft.com/free-developer-offers/
Run the installation and make sure to select “.Net desktop development”
We will be building WPF applications

once the installation is finished, start Visual Studio, and Create a new Project

In the Search field type “WPF” and select “WPF Application from the list

Name your Project and select “Next”

On “Additional Information” click “Next” and Create the Project.
Once the project is created you will start with a blank Window, called “Main Window” and the XAML code below

There are endless options to customize your code at this point and create incredible apps. I will just make some initial basic customizations and create a simple Demo App for the purpose of showing some controls
The first thing we can do it change the Window title so something else, like Demo App.
Select the element, go to the Properties in the bottom-right corner and change the Property ‘Title’

Then from the left side, we can select the “Toolbox” and start adding some controls, like Checkboxes and others

Each type of element has different controls. I will not be showing all elements, but just 3-4 basic ones. It is important to Name your Elements, as we’ll need the names later for referencing them in our PowerShell Script

Another element, which we can add is the ComboBox, or more-commonly referred to as ‘Drop-down Menu’

You can add options to this element from the ‘Items’ Property

then “ComboBoxItem”

You can select the default Item, by selecting the “Is Selected” checkbox in the items properties
You can also check the form, by running the Solution Build and testing the controls

The last thing I want to mention are the bindings. In order to simplify our script later in PowerShell, the more automation we are able to put in the XAML code, the better.
A Lot of times in your scripts, you’d need to put dependencies between elements. E.g. if Element 1 is selected, Element 2 is not, etc.
This can be done with Bindings in XAML.
Let’s put a simple binding on the Checkbox 1 Element and instruct it to be selected, when Checkbox2 is selected

Now if you build your solution again, the element will be automatically selected, when the second one is

Last, let’s put a Status Bar and then we can go to the second part of the article and write some PS code 🙂

Continues in Part 2