I have to confess, I just didn't get PowerShell. .NET at the command prompt was interesting, but why not just write a console application to do the same stuff? I'd still prefer that for many tasks, but think of PowerShell as a replacement for the command line and batch files. Probably the coolest thing about it, though, is the way commands can be glued together. You're no longer constricted to working with strings- type 'dir' and you get a list of FileInfo objects
formatted as string. You can pipe those FileInfo objects to another command, which works against those objects:
dir | sort Length -desc| select Name, LengthThe above sorts the list by the length property, and selects the name and length property for display. Keep in mind these are
.NET FileInfo (and DirectoryInfo) objects. You can do the same for any .NET type, and access any method or property just as you would in VB or C#:
dir | foreach { $_.GetType() }Where it gets cool is when use those other types .NET provides:
$webclient = new-object System.Net.WebClient
$diggFeed = $webclient.DownloadString("http://digg.com/rss/containertechnology.xml")So, now the $diggFeed variable contains digg.com's rss feed as a string. Cool, but it's more useful as XML:
$diggFeed = [xml]($webclient.DownloadString("http://digg.com/rss/containertechnology.xml"))
$diggFeed.rss.channel.item | select titleNote that the xml is "serialized" and usable as though it were an object. So, I can play with the xml data like this:
$diggFeed.rss.channel.item | where { $_.title -like "*.NET*"} | select titleAnd viola- 3 lines of code to get all the .NET posts on digg. Keep in mind we could then copy those to our own rss or do just about anything else with them.
Anyway,
get PowerShell and use it instead of the old C:\. For more stuff you can do, check out the
MSDN PowerShell site. I suspect we'll be seeing more of it used in conjuction with Visual Studio to assist in build scripts and configuration tasks.