Building a GUI using Windows Forms

The first option that we will discuss is Windows Forms. To utilize Windows Forms, we first need to load the respective assemblies. We can load the assemblies by using the following techniques:

[void][System.Reflection.Assembly]::LoadWithPartialName
("System.Drawing")
[void][System.Reflection.Assembly]::LoadWithPartialName
("System.Windows.Forms")

Alternatively, we can use the following technique:

Add-Type -AssemblyNameSystem.Windows.Forms
Add-Type -AssemblyNameSystem.Drawing

Once the assemblies are loaded, we need to load the visual styles method as well. We can load the module by using the following method:

[void] [System.Windows.Forms.Application]::EnableVisualStyles()

I prefer using [void] to add the assemblies ...

Get Mastering PowerCLI now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.