My Solution: August 2015 PowerShell Scripting Games Puzzle

A couple of months ago, announced that the PowerShell Scripting Games had been re-imagined as a monthly puzzle. In August, the second puzzle was published.

The instructions stated that a one-liner could be used if you were using a newer version of PowerShell. A public JSON endpoint can be found at and your goal is to write some PowerShell code to display output similar to the following:

Try to accomplish this with a one-liner but use full cmdlet and parameter names. Write an advanced function that’s a wrapper for this endpoint.

Here’s my one-liner solution. It requires PowerShell version 3 or higher:

I decided to write a reusable tool and create a script module out of it named “MrGeo” that I could add additional Geolocation related functions to in the future:

Notice that in the previous code I added my initials (Mr) as a prefix for the noun to help prevent name collisions with other people’s functions that are named the same thing. I also added additional functionality so that in addition to retrieving the information for your current public IP address, that one or more public IPv4 or IPv6 addresses could be specified. Comment based help has been included along with verbose output. Pipeline input is accepted for the IPAddress parameter and the [ipaddress] type accelerator is used to perform parameter validation for both IPv4 and IPv6 addresses for that parameter.

I created custom formating for the module to display the required output plus the IP address by default for both table and list output but additional data can retrieved by simply piping to Select-ObjectFormat-Table, or Format-List and specifying -Property * or specific properties without having to modify the function itself.

As a best practice, always create a module manifest when creating a PowerShell module:

Notice that PowerShell version 3 is specified in the manifest as the minimum version required by this module. The custom format ps1xml file is also specified in the manifest. If you plan to publish your module in a NuGet repository with PowerShellGet that ships in PowerShell version 5, you’ll need to specify an author and description in the manifest.

Give it a try with both IPv4 and IPv6 addresses and both pipeline and parameter input:


One of the reasons I prefer to place functions like this in a PowerShell script module is that with PowerShell version 3 and higher, you can simply call the function and the module will auto-load as long as it exists in the $env:PSModulePath. No need to remember or figure out where you saved that ps1 file that contains the function and no need to dot source it.

The MrGeo PowerShell script module shown in this blog article can be downloaded from my Scripting Games repository on GitHub.

Also, be sure to see the official 2015-August Scripting Games Wrap-Up article on for more information and solutions for the August scripting games puzzle.


Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: