A PowerShell Cross-Platform Challenge

As PowerShell 7 draws near, built on the successes of PowerShell Core, you will be asked to create PowerShell tools that work cross-platform. Or you may be asked to create a PowerShell tool to run on a non-Windows platform. Your command should still be centered on writing objects to the pipeline. Even if the source material is all text. As a reference take a look at https://jdhitsolutions.com/blog/pslinux/6855/powershell-scripting-for-linux-is-still-about-the-objects/ .

The Challenge

Your goal is to take the output from the Linux uname command and turn it into an object.

Each element corresponds to a piece of system information. Hint – uname –help

Requirements

You should write a function that writes an object to the pipeline based on the uname command. Property names should not have spaces or characters. Don’t use kernel-release. It should be KernelRelease so similar. Your command should work locally on a Linux platform. Bonus points if you can incorporate remoting using SSH so that you can query a Linux system from a Windows platform.

For extra-special bonus points, include a definition of a few default properties or a formatting ps1xml file.

There are probably a few ways you can approach this challenge. As usual, please don’t submit any code solutions. Instead post links to your work such as your blog or Github. Good Scripting.


2 Replies to “A PowerShell Cross-Platform Challenge”

  1. thedavecarroll

    I have a solution, but I don’t like that I call uname for each CLI option. It seemed the cleanest way to get at each property.

    Also, to clarify, the –help and –version output is simply text.

    https://gist.github.com/thedavecarroll/fd01baea04a63f734431a85865602389

    I also did some preliminary work on a ConvertFrom-* function, but had trouble when validating pipeline input from the command’s results. I couldn’t figure out a way to capture the stderr from the command when someone enters an incorrect option.

    Please feel free to post any comments on the gist. Sample output from WSL Ubuntu and MacOS are posted at comments to the gist.

    Thanks!

Comments are closed.