PowerShell Out-Null vs. $null

It’s always the little things. I was recently troubleshooting a slow PowerShell script which required piping the output of a long-running command to Out-Null. Now there may have been other ways to avoid this, but that’s another story.

A quick Google search led to *tons* of articles and posts on why never to use Out-Null (OK, there are reasons, but my particular use was not one of them) and instead redirect to $null.

So I swapped out | Out-Null for > $null and sure enough problem solved.

Here’s a quick snippet that shows the speed difference:

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.