Monthly Archives: September 2007

Effective PowerShell Item 9: Regular Expressions – One of the Power Tools in PowerShell

Windows PowerShell is based on the .NET Framework.  That is, it is built using the .NET Framework and it exposes the .NET Framework to the user.  One very nice feature of the .NET Framework is the Regex class in the System.Text.RegularExpressions namespace.  … Continue reading

Posted in Effective PowerShell | 2 Comments

Effective PowerShell Item 8: Output Cardinality – Scalars, Collections and Empty Sets – Oh My!

In the last post Effective Powershell Item 7: Understanding "Output", we covered a lot about PowerShell output.  However there is a bit more you need to understand to use PowerShell effectively.  This post concerns the cardinality of PowerShell output.  That … Continue reading

Posted in Effective PowerShell | 9 Comments

Effective PowerShell Item 7: Understanding “Output”

In shells that you may have used in the past, everything that appears on the stdout and stderr streams is considered "the output".  In these other shells you can typically redirect stdout to a file using the redirect operator ‘>’.  And … Continue reading

Posted in Effective PowerShell | 10 Comments

Effective PowerShell Item 6: Know What Objects Are Flowing Down the Pipe

To use Windows PowerShell pipes effectively, it really helps to know what objects are flowing down the pipe.  Sometimes objects get transformed from one type to another.  Without the ability to inspect what type is being used at each stage … Continue reading

Posted in Effective PowerShell | 1 Comment

Interface Design: Pragmatism vs Dogmatism

Someone pointed out this blog post to me: http://kirillosenkov.blogspot.com/2007/08/choosing-interface-vs-abstract-class.html The following quote concerns me: "An interface should define at most one member." I cringe at hard-and-fast rules like this.  I understand the author’s sentiment but I guess I would have … Continue reading

Posted in Software Development | 2 Comments

Effective PowerShell Item 5: Use Set-PSDebug -Strict In Your Scripts – Religiously

Windows PowerShell is like most dynamic languages in that it allows you to use a variable without declaring its type and without having assigned to it.  This is handy for interactive use, you can do stuff like this: PS C:\Temp> … Continue reading

Posted in Effective PowerShell | 5 Comments

Effective PowerShell Item 4: Commenting Out Lines in a Script File

OK the last couple of items have been long.  I promise a short one here.  Windows PowerShell doesn’t provide multiline comments.  Multiline comments come in handy when you need to comment out multiple lines in a script file.  However there is a reasonable … Continue reading

Posted in Effective PowerShell | 1 Comment

Effective PowerShell Item 3: Know Your Output Formatters

I have mentioned previously that Windows PowerShell serves up .NET objects for most everything.  Get-ChildItem (alias Dir) outputs a sequence of System.IO.FileInfo and System.IO.DirectoryInfo objects output.  Get-Date outputs a System.DateTime object.  Get-Process outputs System.Diagnostics.Process objects and Get-Content outputs System.String objects (or arrays of them based on how … Continue reading

Posted in Effective PowerShell | Leave a comment

Effective PowerShell Item 2: Use the Objects Luke. Use the Objects!

Using Windows PowerShell requires a shift in your mental model for how command line shells deal with information.  In most shells like CSH, Korn shell, BASH, etc you deal primarily with information in text form.  For instance the output of ls or … Continue reading

Posted in Effective PowerShell | 5 Comments

Effective PowerShell Item 1: The Four Cmdlets That are the Keys to Finding Your Way Around PowerShell

I have been a big fan of the Effective series of books over the years from Effective COM to Effective XML.  Without trying to be too presumptuous, I thought I would capture some of the tidbits I’ve picked up over the … Continue reading

Posted in Effective PowerShell | 2 Comments