Skip to content

PowerShell

But I AM the administrator

A while back I was helping a co-worker with a project where the customer needed to automate a lot of minor Windows configuration steps on some Windows IoT server appliances. One of the tasks was to make it possible to disable Windows Firewall, because even an administrator was greeted with the message "For your security, some settings are managed by your system administrator" and the option to change firewall settings was disabled.

Image Comparison

I recently came across a couple of blog posts on image comparison algorithms shared by Dr. Neal Krawetz. One of them, titled "Kind Of Like That", describes the "dHash" algorithm which generates a perceptual hash based on gradients in the image. With more than 200k family photos to wrangle, I wrote up a PowerShell implementation to find similar images and it works surprisingly well!

Parse Code from Markdown Files

Screenshot of Pester test output highlighting the use of aliases within markdown documentation code blocks

Introduction

Are you testing your documentation? If you write PowerShell scripts or modules, you are hopefully using Pester to test your code. And if you use PlatyPS to generate markdown documentation like I do, then you have a bunch of example PowerShell code sitting in .md files. But what happens if you rename a command, a parameter, or make a breaking change?

Generate markdown tables from PowerShell

I had a need to generate a markdown table dynamically from PowerShell, so I wrote a flexible function which uses the properties on the incoming objects to define the column names, supports the definition of maximum column widths, and outputs either pretty-printed markdown with padded values and aligned columns, or "compressed" markdown without the unnecessary padding included.

Debugging ConvertTo-Json

PowerShell terminal showing a duplicate key error when using ConvertTo-Json

My co-worker, Jared, who regularly uses MilestonePSTools and builds tools with it brought me an interesting problem yesterday - an apparent compatibility issue between our SDK and the ConvertTo-Json cmdlet from the built-in Microsoft.PowerShell.Utility module. If you've ever struggled with the error "ConvertTo-Json : An item with the same key has already been added.", follow along as I share our debugging process until we finally discovered the root cause. While the details in this post involve the Milestone SDK and the MilestonePSTools module, the root cause and the process of finding it is relevant to anyone using .NET assemblies or 3rd party modules with PowerShell.

Argument Transformation Attributes

Introduction

Argument transformation attributes make it possible to offer your users some flexibility in how they supply values for parameters. I've started to use these in the MilestonePSTools module to make it possible to provide a name instead of a strongly typed object like a [RecordingServer] or a [Role], while still making it clear in the Get-Help documentation what the expected object type is, and without polluting functions with object transformation code.

Your users deserve argument completers

Introduction

One of the things I love about PowerShell is the focus on usability and discoverability. The PowerShell team, and the community, have invested so much into reducing friction and accelerating your workflow. Argument completers are one of the tools available to you, and you should consider adding them to your projects if you aren't doing so already.