O'Reilly logo

Pro Windows PowerShell by Hristo Deshev

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

4.3. Processing Pipeline Input

Until now, we have used blocks to encapsulate executable actions and expressions. In the previous chapter, you saw how you can pass script blocks to cmdlets and invoke them for every item in the pipeline. To refresh your memory, look at the following example, which passes a block to the ForEach-Object cmdlet to get the last write dates for all text files:

PS> dir *.txt | ForEach-Object { $_.LastWriteTime.Date }

Friday, September 14, 2007 12:00:00 AM
Thursday, September 13, 2007 12:00:00 AM
Saturday, July 07, 2007 12:00:00 AM

Now, let's dig deeper! Cmdlets are not the only objects that can work with the input pipeline—we can make script blocks do that too. Each script block can contain three special sections that ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required