Filtering Cmdlets

PowerShell also has a few useful filtering cmdlets:

Image Where-Object (alias where and ?)—Participates in a pipeline by helping to narrow down the objects passed along the pipeline based on some specific criteria.

Image ForEach-Object (alias foreach and %)—Participates in a pipeline by applying a scriptblock to every object passed along the pipeline.

By looking at a few files and a directory contained within a test directly, we can easily demonstrate the use of both cmdlets:

PS C:\book> dir    Directory: Microsoft.PowerShell.Core\FileSystem::C:\book ...

Get Microsoft® SQL Server 2012 Unleashed 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.