My First PowerShell
The PowerShell team once requested everyone to blog your initial powershell experiences, and after a personal appeal, how can I refuse! I thought maybe enough time had passed that they weren't interested. (maybe I'll even get more ego boosting posts. Can I believe stuff like that? I'm new to blogs. But it's a fun thought)
I was already a big .Net fan and had heard (but forgotten) about PowerShell until our IT guy suggested it for a problem I was having. The hype was promising (object manipulation instead of string parsing! egads!). I read lots, the install was simple and I started playing around. After a few days I forced myself to switch my always-on shell window to PowerShell instead of cmd.exe.
The manuals that came were helpful to start, although I learned most of the basics from online articles. I wish a more complete user manual (that had syntax examples of scripts for example) would come by default. It feels like the product shipped without help. Although, the get-help command within PowerShell is fantastic. You guys did an awesome job with the contents of get-help.
As a asp.net developer I was more interested in the file-manipulation stuff that could help us with out daily build and .net1.1 -> 2.0 migration. Within less then 2 day I switched us from .bat files to .ps1 files, PowerShell was that good. It saved me time and gave me new options almost instantly. It was the reason I first started this blog.
I love that everything is .Net objects, I love the piping of commands ala unix. It's like being able to work with sql-like commands (ie, set operations) but with any .net object -- fantastic! It scaled from quick & dirty admin-style scripts to full programatic logic control features, exceptions.
And so perl like. Ugh. That took me a while to get over. Why is the command "." instead of a descriptive "include" keyword? to continue the glorious cryptic command-line traditions?
Oh, and the biggest headache I've had thus far? Calling existing command-line tools from powershell. Passing parameters with spaces always seems to break things as PowerShell interprets variables it's way, instead of the way my mental-model expects them too. Which, I guess, is more .bat file like; expecting environment variable-expansion. So, given that you've got a file called listparams.bat:
echo parameters were %*
and the command
.\listparams.bat -buildfile:hi.txt
in cmd.exe, it yeilds
parameters were -buildfile:hi.txt
but in Powershell.exe it yields
parameters were -buildfile: hi.txt
notice the space in the output.
These subtle differences are very frustrating. This particular example is painful when using nant and it's -buildfile: parameter.
Overall I like PowerShell though. Fan-frakking-tastic.
Thanks. This is helpful.
Jeffrey Snover [MSFT]
Windows PowerShell/MMC Architect
Visit the Windows PowerShell Team blog at: http://blogs.msdn.com/PowerShell
Visit the Windows PowerShell ScriptCenter at: http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx