Skip to content
Menu
The Lonely Administrator
  • PowerShell Tips & Tricks
  • Books & Training
  • Essential PowerShell Learning Resources
  • Privacy Policy
  • About Me
The Lonely Administrator

PowerShell Weather Module

Posted on July 26, 2010

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".

Manage and Report Active Directory, Exchange and Microsoft 365 with
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.


Behind the PowerShell Pipeline

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on Mastodon (Opens in new window) Mastodon
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to print (Opens in new window) Print
  • Click to email a link to a friend (Opens in new window) Email

Like this:

Like Loading...

Related

8 thoughts on “PowerShell Weather Module”

  1. Pingback: Tweets that mention PowerShell Weather Module | The Lonely Administrator -- Topsy.com
  2. Andy Tearle says:
    August 7, 2010 at 9:20 pm

    Excellent, elegant, Thanks | JH

  3. David Rees-Clark says:
    August 12, 2010 at 6:57 am

    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

    1. Jeffery Hicks says:
      August 12, 2010 at 8:52 am

      Thank you for the support. Look for a blog entry this morning on modules.

      1. David Rees-Clark says:
        August 14, 2010 at 5:45 am

        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?

  4. Jeffery Hicks says:
    August 14, 2010 at 8:23 am

    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.

    1. David Rees-Clark says:
      August 15, 2010 at 9:08 am

      Thanks. Now it works. Would help if I read the help in the first place.

  5. Jeffery Hicks says:
    September 2, 2010 at 6:47 am

    I came across another online tool for discovering you woeid at http://isithackday.com/geoplanet-explorer/

Comments are closed.

reports

Powered by Buttondown.

Join me on Mastodon

The PowerShell Practice Primer
Learn PowerShell in a Month of Lunches Fourth edition


Get More PowerShell Books

Other Online Content

github



PluralSightAuthor

Active Directory ADSI Automation Backup Books CIM CLI conferences console Friday Fun FridayFun Function functions Get-WMIObject GitHub hashtable HTML Hyper-V Iron Scripter ISE Measure-Object module modules MrRoboto new-object objects Out-Gridview Pipeline PowerShell PowerShell ISE Profile prompt Registry Regular Expressions remoting SAPIEN ScriptBlock Scripting Techmentor Training VBScript WMI WPF Write-Host xml

©2025 The Lonely Administrator | Powered by SuperbThemes!
%d