Book Image

PowerShell Troubleshooting Guide

By : Mike Shepard
Book Image

PowerShell Troubleshooting Guide

By: Mike Shepard

Overview of this book

Table of Contents (15 chapters)
PowerShell Troubleshooting Guide
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Filter left


As discussed in Chapter 1, PowerShell Primer, pipelines are a central feature of PowerShell. Cmdlets can sometimes create a tremendous amount of data though, and pushing that data through a pipeline does have performance implications in terms of memory and processor usage. Filter left is the principle that objects should be filtered as early as possible in the pipeline. Since pipelines flow from left to right, the filter should be as far to the left as it can be.

For example, the following pipelines have the same results and to show the SQL Server datafiles (*.mdf) in order of size:

Even though the results are the same, the execution is about as different as possible. The first pipeline collects all of the files on the disk into a collection, sorts that list, and then selects the .mdf files. The second passes all of the files on the disk again, but filters them before sorting. The third example only creates objects for the .mdf files and only sorts those objects.

Using the Measure...