Since I had fun using the Bing Maps API in C# (see Bing Maps - Geocoding and Imagery), I decided to try and do the same in PowerShell. This didn’t seem to be very hard either, as it’s possible to use the same objects as you would in a regular .NET application. Go PowerShell! The only difference is the web service trick on the second line.

$key = "apikey";
$ws = New-WebServiceProxy -uri http://dev.virtualearth.net/webservices/v1/geocodeservice/geocodeservice.svc?wsdl;
$wsgr = New-Object Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy1ervice_geocodeservice_svc_wsdl.GeocodeRequest;

$wsc = New-Object Microsoft.PowerShell.Commands.NewWebserviceProxy.AutogeneratedTypes.WebServiceProxy1ervice_geocodeservice_svc_wsdl.Credentials;
$wsc.ApplicationId = $key;
$wsgr.Credentials = $wsc;

$wsgr.Query = 'Brussels, Belgium';
$wsr = $ws.Geocode($wsgr);

$wsr.Results[0] | select {$_.Address.FormattedAddress}, {$_.Locations[0].Longitude}, {$_.Locations[0].Latitude};

When you execute this in PowerShell, it looks like this:

Geocoding in PowerShell
Geocoding in PowerShell

Things like this make you think about the power of PowerShell. If you can do it in .NET, you can do it in PS!