Learning PowerShell – Create a GUI

PSSvrMgr_BannerEarly in my journey to learn PowerShell, I came across a hurdle that many people do when learning something new – how can I use it? What can it do for me? I stumbled on this for a while. I needed something that I could do to practice and help realize just what is possible with PowerShell.

At some point I stumbled upon a blog post from @alanrenouf where he describes creating a simple GUI using PowerShell. You can find the original post here. This interested me greatly as I could now envision other folks running my scripts; even folks with little to no PowerShell experience at all. At the time I had also started creating small individual scripts that would gather information from Windows systems, typical stuff like OS, disk, shares and user information. I decided it was time to try and combine these two ideas and see where they lead me.

Creating a GUI

For those of you who have attempted to create a GUI with PowerShell understand that there is a lot of code involved.  Not necessarily complex code – just a lot of it. Luckily Sapien (and I’m sure others) has created tools to make this process much easier. Their PowerShell Studio product is one of the best and includes a tool formerly known as PrimalForms. PowerShell Studio is an incredible tool for making PowerShell GUI code, the only issue is the price (top tools demand top prices!).  Luckily they have also produced a free version known as PrimalForms Community Edition. As I am writing this post it seems they have removed the download link and replaced it with a page that reads “Keep calm, it’s coming soon” – I hope this means they are updating the tool and not discontinuing it! With enough Google-foo I have no doubt a copy of the community edition can be still found.

Now the PrimalForms Community Edition does have some drawbacks, as does 99% of free, trimmed down versions of software, but if you want to just get your hands dirty and see what it’s all about, it is awesome.

Putting it all together

Now that I had a reason to use PowerShell – creating a GUI interface that would gather data from Windows machines – I set out to build a monster. Why a monster? Well, not really my intention but ask anyone who builds anything without much of a plan and a monster is what you’ll get.

I’m not going to be posting the code for this project this time around, I just wanted to show what was possible. The code is ugly. Very ugly! And it shows my progression of working with PowerShell. Knowing what I know now…as the saying goes…I would do it all completely different. I’m just not sure I’ll find the time to rewrite it properly without some kind of justification. In its current state, the code weights in at 7282 lines! Mind you, roughly 4100 lines are dedicated to the GUI alone. This is where PrimalForms comes in very handy!!

To my surprise

I had been working on this project for a few months when one night I was searching for some help and came across the LazyWinAdmin project. This is an extremely well done project along the same lines as to what I was trying to accomplish. My initial reaction was…my project is dead…someone has already beat me to the punch…why recreate the wheel? Though while Francois-Xavier Cat’s project was much more polished than mine, it still lacked something I was striving for – the ability to use any credential, not just assuming that the systems I want to manage are available from the script host. In my previous experiences I have always needed to jump this particular hurdle…never had the luxury of having a single domain or a single set of keys to the kingdom.  So I kept going…and I’m glad I did. Because I created a better script? Heck no! Because I continued down the path I originally started on – to get more hands on and learn more about PowerShell and what I could do with it.

The results

Here are a few screen captures of what I was able to create. Nothing really earth-shattering or new here but highlights what can be done with PowerShell if you put the time and effort in. I hope to encourage other folks to just pick something to play with…you never know what you’ll learn in the process!

PSSvrMgr_OpenPSSvrMgr_InfoPSSvrMgr_DisksPSSvrMgr_SharesPSSvrMgr_UsersPSSvrMgr_ProcessesPSSvrMgr_ServicesPSSvrMgr_Events

Advertisements

One thought on “Learning PowerShell – Create a GUI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s