Thursday, 15 November 2012

Random Holiday destinations in Powershell

We can probably list all the recognised countries in the world by pulling out all of the timezone and internationalization data burned into Windows. To list all windows cultures

But we want to focus on just the country names, so lets move on to
[System.Globalization.Cultureinfo]::getcultures([System.Globalization.CultureTypes]::SpecificCultures)| ?{$_.englishname -eq "English (United Kingdom)"}|fl
Which produces this:
Parent                         : en
LCID                           : 2057
KeyboardLayoutId               : 2057
Name                           : en-GB
IetfLanguageTag                : en-GB
DisplayName                    : English (United Kingdom)
NativeName                     : English (United Kingdom)
EnglishName                    : English (United Kingdom)
TwoLetterISOLanguageName       : en
ThreeLetterISOLanguageName     : eng
ThreeLetterWindowsLanguageName : ENG
CompareInfo                    : CompareInfo - 2057
TextInfo                       : TextInfo - 2057
IsNeutralCulture               : False
CultureTypes                   : SpecificCultures, InstalledWin32Cultures, FrameworkCultures
NumberFormat                   : System.Globalization.NumberFormatInfo
DateTimeFormat                 : System.Globalization.DateTimeFormatInfo
Calendar                       : System.Globalization.GregorianCalendar
OptionalCalendars              : {System.Globalization.GregorianCalendar, System.Globalization.GregorianCalendar}
UseUserOverride                : True
IsReadOnly                     : False
And is clearly just a list of locales :-(
We want a political listing, this list has only got 210 locales.
OK, so that was fun, but did not produce the answer we wanted, so here is a possible solution if you do have an internet connection at the time you want the actual data.
It's a web-service, and the logical choice for live data. If you are paranoid like me, an interresting test-case is to validate a recently added country, such as 'South Sudan' named in July 2011. So now you are starting to squeek, help, I can't use web services in Powershell! Whoa!!!!  Nope, remember this is Powershell, and anything BASH can do, this can do also; so lets get moving.