Powershell and the web

Lately I have been playing with PowerShell to see if it can help with some uptime/availability checks for our web sites and services at work; Yes i know what you are thinking but I’m not a sys-admin and I need to know if my stuff is working with out having access to the server… long story I’m sure you will appreciate.

In my reading I have seen lots of flaky posts about PowerShell and web services. I think people need to remember that web services still conform to the http protocol, there is no magic, you do not need to access any visual studio dll or do any weird crap like that, you just need to hit the url and receive a payload.


$wc = new-object system.net.WebClient
$webpage = $wc.DownloadData($url)

That’s it. No weird proxies no importing custom dll’s.

Here’s an example calling the Google Maps API (which is a nice API BTW) to get a latitude and longitude of an address, specifically Perth’s craziest bar Devilles Pad (think Satan living in a trailer park that hangs out at a Go-Go club that used to be a James Bond-villians liar, yeah its that cool:


$url = "http://maps.google.com/maps/api/geocode/xml?address=3+Aberdeen+St,+Perth,+WA+6000,+Australia&sensor=false"
$wc = new-object system.net.WebClient
$webpage = $wc.DownloadString($url)#Edit -Thanks Ken
$xmldata = [xml]$webpage
$lat = $xmldata.GeocodeResponse.result.geometry.location.lat
$lng = $xmldata.GeocodeResponse.result.geometry.location.lng
write-host "Latitude = $lat - Longitude = $lng"

Like that? Go play: Google Maps API Doco

WS… not so interoperable..

from Udi:
http://feeds.feedburner.com/~r/UdiDahan-TheSoftwareSimplist/~3/127874396/

“…So imagine my surprise when we “Web Service-ized” a bunch of Java components that exposed just that kind of interface, and it didn’t work. After mucking around for almost the whole day, we started returning to basic principles. We started throwing out parameter after parameter, structure after structure, until we were left with something that should have just worked:
string SomeFunction(char c);
But it didn’t.
This was ridiculous. If Web Services couldn’t give me interoperability at this most basic level, I swore that the whole thing must have been a conspiracy. After some ill-mannered googling, I found out that:
The Java char datatype is not supported because of an omission in XML Schema…”