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 ...

Get Pro Windows PowerShell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.