Creating XAML GUIs with PSGUI

PowerShell is a scripting / programming language designed primarily to automate specific operational tasks in combination with other technologies and services. But we often read that IT pros and administrators are asking for graphical user interfaces. Even today, there are more administrators out there who prefer GUIs over coding techniques.

We have good news for this majority—it is possible to create GUIs with PowerShell that execute PowerShell code in the so-called CodeBehind. There are two frameworks available for use—you can either use Windows Forms or XAML/WPF. XAML is the newer technique, and has some advantages. David has been working for a decent time on a dedicated module to create and demonstrate XAML UIs. You can easily install it on your Windows machine as follows:

#Installing PSGUI
Find-Module PSGUI
Install-Module PSGUI

#Importing PSGUI
Import-Module PSGUI

#Starting main user interface
Start-PSGUIManager

This will open up the PSGUI-Manager, which is also written in PowerShell, and is shown in the following screenshot:

In the preceding screenshot, the 01_UserInput dialog is selected. In the Dialogs field, all the available dialogs are shown. You can now take a dedicated look at each of those examples. As the PSGUI-Manager is itself created as a PowerShell UI, you can also take a dedicated look at its code. 

The user interface is split up into three files, as follows:

  • XAML: Clean XAML code for the UI, which can be created with Visual Studio
  • CodeBehind: PowerShell code to handle all the events and fill the UI with life
  • Functions: Additional PowerShell modules/functions

In the variables area, you can see the variables named and created for this user interface, along with the specific object type of each. In the upper-right corner, you can see the available events for the selected object. Already created events are marked in bold, and you can easily create new events by double-clicking on the wanted event. Double-clicking on an already created event such as Click will jump to the code implementation of this event.

In addition, you can also render specific dialog examples. Just select one specific dialog and press Ctrl + R. See the following screenshot:

A couple of huge benefits of this implementation are the possibility to create all the variables for a specific dialog and use the IntelliSense of the UI elements within PowerShell, as well as the possibility to debug the dialogs with ISE and look at the values during runtime. 

Complete documentation on the idea behind this project can be found on David's blog at https://powerintheshell.com/category/psgui/.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.61.142