Don’t do that: The following code clean the screen to prevent the output (the index of the item added into the collection) generated by the Add method.
$array = New-Object System.Collections.ArrayList
$array.Add('Item1')
Clear-Host
Do that: In cases like this one, it’s better to use [void] or $null to prevent the output to be displayed.
This code returns an output with “0” (the index of the item added into the collection).
This code returns no output.
$null = $array.Add('Item1')
or
[void]$array.Add('Item2')
Note: There is also a cmdlet “Out-Null” but piping to Out-Null is slower.