After any result returned from the PS command, it is very important to block it for any unimportant results.
We have many ways to implement it, and here are two more special methods. Note that the following two lines try to create a new folder on the C drive:. New-Item will output the object of this folder, but when you are creating the folder you may want to block the created result:
$null = New-Item -Path c:\newfolderA -ItemType Directory New-Item -Path c:\newfolderB -ItemType Directory | Out-Null
So which way is better? It's definitely the first one. The pipeline passes unwanted results to out-null, which will take more time and resources. Of course you don't need to worry about the resources consumed during individual calls, but when in a loop, its effect will be obvious.
So the best way to compare out-null is to use $null.
Supports all PS versions