PowerShell is just awesome

I’ve known for a while that PowerShell is useful but I never got myself to take that two hours to learn to actually use it. Today I did just that. And it’s simply awesome!

Tasks like reading a remote RSS feed can be done with just few lines of code. However the cool part is that these small programs (or cmdlets) can be easily used together.

Maybe the most powerful feature of PowerShell is it’s ability to pipe any collection of objects to an other program as they are. No need for parsing string streams. I would really like to see a portable version of that kind of piping shell — that works on *nix as well as in Windows!

Here’s my test application. It takes an URL for RSS feed as an argument and will return items from it.

param ([string]$url)
$wc = New-Object Net.WebClient
[xml]$resp = $wc.DownloadString($url)
$resp.rss.channel.item

Then you can use it like:

.\rssreader.ps1 http://www.jhh.me/blog/feed/

The raw output from this command to the console is quite detailed since it includes everything:

console

You can pipe the results to Out-GridView to get more graphical presentation of it:

.\rssreader.ps1 http://www.jhh.me/blog/feed/|Out-GridView

Notice that the table is formatted nicely. That’s because the piping is done with real objects instead of outdated string streams.

gridview

Maybe one reason why PowerShell takes time to learn is that it has quite strict security model by default. For example you cannot just write and run that example on your system without signing it or changing default security model. Read more about it from an article Running Scripts at TechNet.

PS: I bought also an ebook of O’Reilly’s PowerShell for Developers. I think it’s much softer crash course to PowerShell than most online articles.

Fork me on GitHub

About jhh

Programmer, business owner and a system admin. I post about books, business, Internet, technology and pretty much anything interesting, too.
This entry was posted in Programming, Software, System Administration, Web development & design. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Anti-Spam Quiz: