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.

11.1. Making the shell give you just what you need

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.

11.2. Filtering left

11.3. Using comparison operators

11.4. Filtering objects out of the pipeline

11.5. Using the iterative command-line model

11.6. Common points of confusion

11.7. Lab

11.8. Further exploration

11.9. Lab answers

sitemap