PowerShell Performance: Filtering Collections

Depending on what version of Windows PowerShell you are running, there are several different methods and syntax available for filtering collections. The differences are not just aesthetic; each one has different capabilities and performance characteristics. If you find yourself needing to optimize the performance of a script that processes a large amount of data, it helps to know what your options are. I ran some tests on the performance of various filtering techniques, and here are the results: Description Syntax Pros Cons Where-Object (-FilterScript) Get-Process | Where-Object { $_.Name -eq 'powershell_ise' } Runs on any version of Windows PowerShell. Streams […]

Great Debate: Pipeline Coding Syles

A good programmer or scripter should always try to produce code that is easy to read and understand. Choosing and consistently applying a strategy for indentation and bracing will make your life, and possibly those of your co-workers, much easier. (Unless, of course, you’re that guy who prides himself in writing code that looks like a cat walked across his keyboard, and cackles any time someone tries to understand it.) Much of PowerShell’s syntax can borrow coding conventions from C-style languages, but the pipeline is something new. Below are two pipelines formatted a few different ways. Which styles do you […]