“SSH is the future and everyone should use it.”
- Joey Aiello, PowerShell PM, PowerShell Conference EU, April 2018
About a month ago, I wrote a post about using my MiniLab Module to easily deploy a new Root and Issuing Certificate Authority (CA) to a Windows Domain using Windows VMs. I was able to simplify things to the point where running one function would take care of everything for you. Unfortunately, even though actually using the function (Create-TwoTierPKI) took about 2 seconds, the operations the function handled (i.e. deploying and configuring Windows VMs to become the new Root and Issuing CAs) took about 3 hours - which is a really long time. So, I wanted to write a post about how to use PowerShell Core, Docker For Windows, and CloudFlare’s CFSSL to turn 3 hours into about 30 minutes (although, you have to do all of the steps yourself as opposed to running a function and doing something else for 3 hours).
Last week I finally decided to rollup my sleeves and attempt to refactor some of my more recent Windows PowerShell 5.1 code to work with PowerShell Core 6.X (on Windows). My goal was to use the WindowsCompatibility Module as efficiently as possible so that I really didn’t have to touch the majority of my existing code. The experience was relatively painless, but I still wanted to share some lessons learned as well as a way to make (most of) your existing code compatible with PowerShell Core by adding only two lines towards the beginning of your script/function/Module.
I knew I wouldn’t start using PowerShell Core (Pwsh) as my primary shell on Windows unless I had an easy way to use Cmdlets/Scripts/Functions/Modules that could only run on Windows PowerShell 5.1 (WinPS). So I decided to write a function that could push all compatible elements of my Pwsh environment to WinPS, and then run the WinPS exclusive operations. As luck would have it, a few hours after I pushed my Get-WinPSInCore function to GitHub, I discovered the WindowsCompatibility Module (version 0.0.1 was released by the PowerShell Team et al. a few days ago). So, I decided to kick the tires on the Module and do some (very limited) comparisons to my Get-WinPSInCore function.