Easier script deployment in PowerShell 2.0

If you can’t tell from reading entries in my blog I’m a bit of a script junkie.  I loathe typing out the same command sequence more than once.  As such I go to great lengths to script as much as possible in life.  I also enjoy sharing my scripts with other members of my team….


Test-ItemProperty utility function

I was playing around in the registry the other day and found the PowerShell API lacking in a key area.  There does not appear to be a good way to detect the presence of a Registry Name/Value pair.  All of the operations such as New, Delete, Rename are based off of the program knowing the…


Simulating Closures in PowerShell

Previously I blogged about PowerShell’s lack of closure support within a script block.  This presents a significant hurdle in developing a LINQ like DSL for powershell which I’ve been working on.  Imagine the following syntax $a = from it in $source where {$it -gt 5 } This would be the rough equivalent of the following…


PowerShell LINQ: Take-Count and Take-While

The Take pair of functions are very similar to the Skip functions.  The Take expression does essentially the opposite of the Skip functions.  Skip is useful for getting elements further down the pipeline.  Take is used for getting elements from the start of the pipeline.  #============================================================================ # Take count elements fro the pipeline #============================================================================ function…


PowerShell LINQ: Skip-While

Next up in the PowerShell LINQ series is SkipWhile.  This LINQ function takes an enumerable instance and a predicate.  The function will skip the elements in the enumerable while the predicate is true.  The argument to the predicate is the current value of the enumerable.  The LINQ version takes a predicate in the form of…


LINQ like functions for PowerShell: Skip-Count

The PowerShell pipeline, is fairly similar to C#/VB’s LINQ.  Both filter a group of elements through a series of transformations which produce a new series of elements.  The devil is in the details of course but I’ll get to that in a future post.  When using PowerShell I constantly find myself wanting to use various…


Script Blocks and Closures (or lack there of)

Script blocks are a concise way of representing an expression or statement group in Powershell.  It’s the C#/F#/VB lambda equivalent for PowerShell.  One difference between C#/F#/VB lambda expressions and a scriptblock is the lack of lexical closures (otherwise known as variable capturing).  This feature allows for a variable defined in an outer scope to be…


Script Blocks and Arguments: Figuring it out for myself … again

Script blocks are a powershell construct for storing an expression or group of statements inside an expression.  It’s the equivalent of a C#/F#/VB Lamba expression.  Recently I needed to use a script block but found I had forgotten how to read passed parameters inside the script block.  Forgetting how to use a feature is typically…



With all of the great built-in commands for processing pipelines the absence of a good command to count the number of elements in a pipeline seems to stand out.  The best built-in way to count the number of objects in a pipeline is to convert the value into an array and then take the length….


Sorting out Binary Files

I constantly get tripped up in my powershell scripts/commands because I run them against a binary file.  In particular when I’m searching through a directory structure looking for a particular string or regex.  I’ve found the simplest way to avoid this problem is to use a simple regex check to filter out the known binary…