Update: Added the code in text form, after the jump.
Man, you’ve gotta love PowerShell.
Although I’m mostly into GUI and user experience, I just love console applications.
They’re super fast, powerful, concise, and if written correctly they are also easy to use (there’s that user experience theme again).
If I had to sum up the benefits of PowerShell in one sentence it would be this:
“Object oriented, interpreted, .net enabled , well structured shell and scripting environment.”
To install Windows PowerShell, just go here.
Now have a look at this cool little script I wrote last night.
It uses Yahoo! weather web service to get the local weather (in this example, local means Israel’s international airport, which happens to be close to where I live).
Here’s a snapshot of the script inside PowerGui so you can see all the nice color coding, the actual text is after the jump.Click on the image above to open it full-size and let’s go over the lines real quick.
Line 2: creates a new .NET WebClient object.
Line 3: calls Yahoo’s WebService by downloading the result xml, converting it to a .NET XmlDocument object on the fly.
Lines 5,6,12,13,21-25: get a string value out of an xml node or attribute.
Some other interesting things to consider:
- Lines 8,14 and 26 use the -f formatter, which works basically like C#’s String.Format().
- Also note the pipeline (|) used to manipulate the text color in these lines.
- To get the weather someplace else, all you need to do is modify the url, see their instruction page for more info.
And this is how it looks when I run it:




