I first wrote a Windows PowerShell function several years ago to retrieve weather information via Yahoo's weather service. I've been itching to rewrite it and finally found some time over the weekend. Turns out it's a good thing I did because the method I had been using to query the Yahoo web service has been deprecated. My original version relied on a zip or postal code. But now Yahoo relies on a WOEID or "Where on Earth ID".
ManageEngine ADManager Plus - Download Free Trial
Exclusive offer on ADManager Plus for US and UK regions. Claim now!
The underlying structure of my Get-Weather function hasn't changed much. Using the Webclient object I query the Yahoo web service, retrieve an XML document and parse it. I then write a custom object to the pipeline.
[cc lang="DOS"]
PS C:\> get-weather 12762649
Date : Mon, 26 Jul 2010 7:54 am EDT
Location : Jamesville, NY
Temperature : 67 F
Condition : Partly Cloudy
ForecastCondition : Sunny
ForecastLow : 60 F
ForecastHigh : 80 F
[/cc]
My new version includes a lot more information. The function's default is this basic view. However you can also specify Extended or All. I defined a set or properties and then pipe my custom object to Select-Object specifying the appropriate property set.
Since the new version requires a WOEID, you're probably wondering how to find it. One way is to go to http://weather.yahoo.com/ and enter in your zip code or location in the search box. Your WOEID will be the number at the end of the url that is returned. Or you can use the Get-Woied function. This function takes some sort of search and returns a simple object, including the WOEID.
[cc lang="DOS"]
PS C:\> get-woeid "Detroit,MI"
Country : US
Region : Michigan
Postal :
Locale : Detroit
WOEID : 2391585
PS C:\> get-woeid 68132
Country : US
Region : Nebraska
Postal : 68132
Locale : Omaha
WOEID : 12787550
[/cc]
You can even use the two in a pipeline.
[cc lang="DOS"]
PS C:\> get-woeid 68132 | get-weather -extended
Date : Mon, 26 Jul 2010 6:52 am CDT
Location : Omaha, NE
Temperature : 70 F
Condition : Partly Cloudy
ForecastCondition : Partly Cloudy
ForecastLow : 72 F
ForecastHigh : 88 F
WindChill : 70 F
WindSpeed : 5 mph
Humidity : 84%
Barometer : 30.07 in and steady
Visibility : 10 mi
Tomorrow : Tue 27 Jul 2010 Mostly Sunny Low 74F: High: 94F
[/cc]
I've put everything together in a module, JH-Weather. The module also defines aliases of gwid and gw for Get-Woeid and Get-Weather, respectively. I have some other ideas for the module so stay tuned for future releases. In the mean time you can download a zip file with the module here.
Excellent, elegant, Thanks | JH
Hi!
I have just found your blog while I was googling for the PowerShell profile paths, and I quite like this blog.
Anyway, I do have a question concerning these modules you’re offering for download: What do I do once I downloaded them? Is there a special module folder? How can I actually use this module?
Seems like more than one question, but still I would be very, very thankful for an answer.
FYI: I’m running Windows 7 with PowerShell 2.0
Greetings, David
Thank you for the support. Look for a blog entry this morning on modules.
Hey, thanks for the very quick response. Downloaded and installed (if you want to call it that) the module now. Works wonderfully.
Now, there is one more thing: Can I somehow change the module to display Celsius instead of Fahrenheit?
I don’t have Powershell handy now but look at help for Get-Weather. I thought I had a parameter for that. If not I’ll have to add.
Thanks. Now it works. Would help if I read the help in the first place.
I came across another online tool for discovering you woeid at http://isithackday.com/geoplanet-explorer/