Programming Journey Entry 6: Picking PowerShell back up

All of these Programming Journey posts can be found in the associated category of this blog.


Note: This is a post I wrote a long time ago (nearly two years) and apparently never got back around to. Since I'm picking up PowerShell again...again...I'm posting it. It's a little short (or unfinished), but the next post will make up for it.

PowerShell but more effectively

Back in 2019 I had a not very successful attempt at 100 days of code and it involved a lot of PowerShell. I think forgot most of what I learned from that time. Other than “this seems vaguely familiar”.

I’m not sure what prompted the motivation this time around, but I seem to be fairly consistent with working with PowerShell again.

As was the case in 2019, one of the main issues I have is not having a test environment outside of work. I mean I can write and test things in PowerShell from home but I can’t really know for sure it will work until I try it at work. Which sometimes slows down because of the work part of work.

The good news though is that since 2019 my work’s environment made it to 100% Windows 10 and further those windows 10 machines have been gradually updated to more recent versions of Windows 10 (due to faulty hardware and 10 year old PCs still in use). All this means I can more consistently work with the assumption of at least PowerShell 5.1. There might be some old windows 10 1803 left the in the environment but those are rare enough no issues should come up.

I actually have a plan in the works to resurrect the old Dell R520 server to create a domain and really test this out. Until then I’m just taking small steps and brainstorming.


A Humble start

I started out slowly – just collecting convenient one-liners that help things go a little quicker.

For instance all the PCs in the environment are Dells are we sometimes need the service tag. This tag for instance can be inserted into a URL to bring up the PC’s info, driver download page and warranty status. So one line to simply feed me that service tag for a PC that’s a 20 minute drive away (and I wouldn’t bother trying to ask a user) is very convenient.

Another instance is retrieving a list of currently installed network printers: we use a 3rd part solution for this so all the network printers are already visible for all the user profiles (a big improvement). So one command, again against a PC I can’t necessarily remote into and open the requisite screen to look at, is very convenient.

I also find myself looking for ways to auto-install different applications like VPN software. Because clicking through the series of Next buttons for 1000th time starts to get a little tedious.

So I decided to start a document with my collection of “one liners”. Which isn’t a very accurate title any more since many of them are multiple lines or multiple parts.


Expanding outward

While I was doing all this convenience command collecting I was also trying to brainstorm and putting together some kind of unifying UI to them all.

Either an actual GUI or a simple MS-DOS circa 1985 era menu system for a choose-the-thing style approach. I haven’t actually decided which way to go yet.

I did find out there’s actually two ways to utilize a GUI in PowerShell, which was actually news to me. Unless I mentioned it in a post in 2019, in which case I apparently forgot.

I thought there was only a XAML-based GUI, based on Windows Presentation Foundation. But apparently you can also utilize WinForms – I have a book published in 2013 that refers to WinForms as “really old”.

I kind of like the over simplicity of WinForms – and it still works without any issues – but there doesn’t seem to be a quick drag-and-drop designer solution available for free.

The XAML solution on the other hand has the GUI creator built into Visual studio community edition.

One of the two solutions is one line while the other solution is two lines. I’m going to copy/paste the lines anyway so it shouldn’t actually matter to me. Other than WPF has the convenient GUI designer option to generate the XAML file PS will load in.

About the only argument I have left for WinForms is this really great page on how to create UIs using WinForms, including a template and complete walkthrough on building the script with the UI elements: How to Create a PowerShell Form Generator.

So I think I’m going to reverse course and just use the good old XAML thing.


I think I would like to start utilizing the latest version of PowerShell – PS7 Core I think it’s called – and merely test things with PowerShell 5 as necessary. There are a lot exciting things in PowerShell 7 I think I would like to explore outside of this script, like interfacing with various APIs.


Reference links:


I've made a "clearing house" repo for random python programming projects on GitHub:
https://github.com/tildesarecool/ReallyHadtoPython

One thought on “Programming Journey Entry 6: Picking PowerShell back up

Leave a comment