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.

Script Blocks And Arguments

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.

Case Sensitive Vs Case Insensitive Languages

Just had a random thought while I was looking at some code today. It’s yet another argument in the case sensitive vs. case insensitive language battle.

Count Object

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. For instance take the following script which looks for the word ‘test’ in all of the .ps1 scripts in or below the current directory

$PS> gci 're 'in *.ps1 | %{ ss test $_.FullName } 

Notimplementedexception Vs Notsupportedexception

In responding to a recent blog post, one of the readers, Jeremy Gray, noted that I was using a NotImplementedException where I should have been using a NotSupportedException. At first I did not agree. There was a method on an interface which my underlying object could not implement therefore I felt the choice of NotImplementedException was an appropriate.