More PowerShell Scripting Candy
I hope the recent articles on embellishing your PowerShell code have been interesting and inspiring. Running code in the console doesn't have to be boring and pedestrian. Of course, if your code is being run in a non-interactive session, you might want to consider a different approach. But for those times when you are running code interactively, why not add a little flair? Today, I want to continue with this theme and show you how to create a simple progress bar using ANSI escape sequences.
In the past, I've written scripts that leverage the Write-Progress
cmdlet. However, the progress output is ephemeral. And in PowerShell 7 the new minimal view introduces new challenges. Don't get me wrong. I like Write-Progress
in PowerShell 7, but I need to write code that takes the minimal view into account. My older Windows PowerShell scripts won't show the same information.
That said, let's build an alternative using ANSI techniques. Along the way, we'll also play with custom characters and emojis. All of my samples should be considered proof-of-concept and not production-ready code. But I hope they will inspire you.
Let's get started with something simple and different, a progress spinner. A spinner is a simple way to indicate that something is happening. You've seen this sort of thing in Windows. I want to create one that runs in the PowerShell console.