Chapter 11. Filtering and comparisons
Up to this point, you’ve been working with whatever output the shell gave you: all the processes, all the services, all the event log entries, all the hotfixes. But this type of output isn’t always going to be what you want. Often you’ll want to narrow down the results to a few items that specifically interest you. That’s what you’ll learn to do in this chapter.
The shell offers two broad models for narrowing results, and they’re both referred to as filtering. In the first model, you try to instruct the cmdlet that’s retrieving information for you to retrieve only what you’ve specified. In the second model, which takes an iterative approach, you take everything the cmdlet gives you and use a second cmdlet to filter out the things you don’t want.
Ideally, you’ll use the first model, which we call early filtering, as much as possible. It may be as simple as telling the cmdlet what you’re after. For example, with Get-Service, you can tell it which service names you want:
Get-Service -name e*,*s*
But if you want Get-Service to return only the running services, regardless of their names, you can’t tell the cmdlet to do that for you, because it doesn’t offer any parameters to specify that information.