Finding airports with PowerShell and Local.Live

So a few weeks back i came across this puzzle in an internal discussion list. There is a comma separated text file at AirportsGDM.txt containing all the airports and the codes, along with the Lang and Long Co-ordinates. The puzzle was to see how few lines of code you needed to write a program that would parse the file, find a specific airport, then display a local.live map displaying the airports location.

Sounded like something that Windows PowerShell should be able to do, in say hmm, i don't know, 1 line....

So first the final script

 function Get-AirportMap
 {
     param([string]$aircode)
     get-content D:\dev\airports\AirportsGDM.txt | select-string $aircode | 
 foreach { $a = $_.Line.substring(0,$_.Line.Length-5).replace(",","~") ; [System.Diagnostics.Process]::Start("https://local.live.com/default.aspx?V=2&cp=$a&lvl=12")}
 }

 

This of course assumes you have the text file located in the d:\dev\airports folder.

The command should be fairly straightforward and easy to figure out.

The content of the text file

 get-content D:\dev\airports\AirportsGDM.txt

is pipedinto a selection

 select-string $aircode

for each result we go and work out the co-ordinates

 $a = $_.Line.substring(0,$_.Line.Length-5).replace(",","~") 

Then start a new process navigating to the local.live URL

 [System.Diagnostics.Process]::Start("https://local.live.com/default.aspx?V=2&cp=$a&lvl=12")
 Simple. and the results.
 get-airportmap LAX

 THIS POSTING IS PROVIDED "AS IS" WITH NO WARRANTIES, AND CONFERS NO RIGHTS