Monday, March 24, 2008 2:49 PM bart

Windows PowerShell 2.0 Feature Focus - Splat, Split and Join

Two weeks ago I did a little tour through Europe spreading the word on a couple of our technologies including Windows PowerShell 2.0. In this blog series I'll dive into a few features of Windows PowerShell 2.0. Keep in mind though it's still very early and things might change towards RTW - all samples presented in this series are based on the CTP which is available over here.

 

Introduction

This time we'll take a brief look at a few language enhancements in Windows PowerShell 2.0. There are three such enhancements that deserve a little elaboration at the time of writing:

  • Splat - 'splatting' of a hashtable as input to a cmdlet invocation
  • Split - splitting strings
  • Join - the reserve of split

 

Splat

Splatting allows the entries of a hash-table to be used in the invocation of a cmdlet - more specifically, keys become named parameters and values become input to those parameters. Here's a sample:

$procs = @{name="notepad","iexplore"}
get-process @procs

And the result looks like this:

image

Of course multiple parameters can be specified at once (that's the whole point of the hashtable anyhow):

$gm = @{memberType="ScriptProperty","Property";name="[a-d]*"}
get-process @gm

image

In other words, invocation parameterization information can now be kept and passed around as data.

 

Split and join

Split and join are fairly trivial in fact. These are the equivalents of System.String's split and join operations but now exposed as language-integrated operators.

"bart","john" -join ","
"bart,john" -split ","

image

Simple but oh so handy :-). Have fun!

Del.icio.us | Digg It | Technorati | Blinklist | Furl | reddit | DotNetKicks

Filed under:

Comments

# Windows PowerShell 2.0 Feature Focus - Script Debugging

Wednesday, March 26, 2008 10:18 PM by B# .NET Blog

Two weeks ago I did a little tour through Europe spreading the word on a couple of our technologies including