Scripting Games 2015 event 2

The Scripting Games are back :-D, excellent!

The puzzle of August is live at http://powershell.org/wp/2015/08/01/august-2015-scripting-games-puzzle/
SG2015-August.00

First, you should copy/paste the URL proposed in the puzzle – http://www.telize.com/geoip – into a browser to see what it looks like.
SG2015-August.06

We can see a pretty straight-forward reply formatted in JSON. Nice! This allows PowerShell versions as of 3.0 to use the built-in Invoke-WebRequest cmdlet to get the content of this webpage and the built-in *-Json cmdlets to convert the JSON content into a PowerShell object.
This also allows to solve the puzzle with a simple one-liner:

(iwr "http://www.telize.com/geoip").Content|
ConvertFrom-Json|ft *tude,con*,t*

With all commands and parameter names spelled out:

(Invoke-WebRequest -URI "http://www.telize.com/geoip").Content|
ConvertFrom-Json|Format-Table -Property *tude,con*,t*

That’s fairly easy if you have a recent version of PowerShell, isn’t it. Now, let’s think 2 minutes what you’d have done if you only had PowerShell version 2.0.

Fun? Ugly? Having a recent PowerShell version saves you a lot of time.

SG201508-Wx
Bonus:
If you go to http://www.telize.com , you can read how to interact with the endpoint and that it offers a REST API, which means you can go down another route and use the built-in Invoke-RestMethod cmdlet.

Advertisements

One thought on “Scripting Games 2015 event 2

  1. Pingback: Dew Drop – August 24, 2015 (#2075) | Morning Dew

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s