Powershell Best Practice #12: Avoid Out-Null cmdlet

By | June 28, 2015

Best Practice: It is recommended to avoid Out-Null when you need to suppress the output of some commands inside large loops (for, foreach, etc.) for example.

Explanation:

It is recommended to assign to $null or [void] casting for better performance.

When you want to suppress the output of a command (example: when adding items to a collection), using Out-Null is slow.

Results of a test with a large loop:

measure null powershell


previous-buttonnext-button

One thought on “Powershell Best Practice #12: Avoid Out-Null cmdlet

  1. Pingback: Powershell Best Practice #13: Avoid double quotes in strings if not necessary | Powershell Guru

Leave a Reply

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