It was bound to happen eventually, no matter how much I resisted the idea, eventually I needed a PowerShell script with a GUI. This week I needed a script that allows searching for a VM and selection from a few lists, as well as some optional configuration. I could have written a script that prompted the user for a series of answers, but what I needed was a GUI with a bunch of Windows form controls just like I used to use in Visual Basic. The good news is that there is a pretty web application for designing precisely this purpose and generating a PowerShell script skeleton that you can fill out with your application code. I used POSHGUI.com to create the web form part, then put together the main script logic as usual.
Poshgui has a drag-and-drop GUI Editor; you drop Windows form elements onto a form just like Visual Studio forms designer. You can edit the properties of form objects and select which events you would like to have added to the skeleton code; you can also choose to have the event trigger a function that is defined elsewhere in your code. This last is important; you are going to need to make changes to the form in POSHGUI and then feed those changes back into your script. This will be a pain; the POSHGUI code editor is very limited. I ended up simply copying the whole skeleton out and pasting it into my script, calling functions from the GUI events is much easier than putting your code in the skeleton events. The skeleton code is quite easy to read, it is laid out and grouped by each control that you place.
You can save your forms once you have setup your POSHGUI account. Saved forms can be re-opened and edited as required. There does not seem to be a way to upload your form code into POSHGUI, so sharing a form privately is a little tricky. There is a public repository of forms, and it appears that the default is that your form is also shared in this repository.
This forms designer does use Windows forms, so I don’t expect that the generated GUI could be used on a MAC or Linux machine with PowerShell core. Not a big issue for me as I have a bunch of Windows VMs which I use for these development projects.
I expect to use POSHGUI for at least one more project, where I can avoid needing to use Visual Studio and all the extra things that it likes to install. A nice visual forms designer is really helpful in avoiding more heavyweight languages for system administration tasks.
© 2018, Alastair. All rights reserved.