PowerShell v2 Pipelining in 73 (make that 53) Characters

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