PowerShell v2 Pipelining in 73 (make that 53) Characters

PowerShell v2 Pipelining in 73 (make that 53) Characters

  • Comments 3

I started using Twitter and saw a request from Thomas Lee for help about pipelining in CTP3.  The thing about Twitter is that the messages have to be tiny so I wasn’t sure I could answer using it.  It turns out I can solve this problem AND give a usage example in 73 characters.  Here goes:

PS> function t{param([Parameter(ValueFromPipeline=1)]$t);process{$t}};1..10|t
1
2
3
4
5
6
7
8
9
10

Now if you put it into a file (which is actually what Thomas asked for), then it is only 53 characters:

PS> cat t.ps1
param([Parameter(ValueFromPipeline=1)]$t);process{$t}
PS> cat t.ps1 |Measure -Character

Lines              Words                      Characters Property
-----              -----                      ---------- --------
                                                      53

PS> 1..10 |.\t.ps1
1
2
3
4
5
6
7
8
9
10

Enjoy!

Jeffrey Snover [MSFT]
Windows Management Partner 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

Leave a Comment
  • Please add 7 and 3 and type the answer here:
  • Post
  • Maybe I'm being dumb, but what's the significance of process{$t}?

  • I can do it in 31 characters:

    function t {process{$_}};1..9|t

  • Make that 19:

    filter t{$_};1..9|t

Page 1 of 1 (3 items)