After any results returned from the PS command, it is important to shield them for any unimportant result.
There are a number of ways to implement it, and here are two more specific methods. Note the following two lines try to create a new folder in C disk:. New-item will output the object of this folder, but when you create a folder you may want to mask the results of the creation:
$null = New-item-path c:\newfolderA-ItemType directory
new-item-path c:\newfolderB-ItemType Directory | Out-null
So which way is better? Must be the first one. The pipeline passes unwanted results to out-null, which consumes more time and resources. Of course, you don't have to worry about the resources that are consumed by individual calls, but when you're in a loop, the effect will be obvious.
So the best way to compare out-null is to use $null.
Supports all PS versions