I want to test if New-Item throws an error, for which i am using the -WhatIf parameter and catch the error if an error occurs. If no error occurs, i dont want the -WhatIf output in my console.
I tried the following, but the "WhatIf:"-Output still gets printed to the Powershell console:
New-Item -Path $Path -Name $Name -ItemType $ItemType -ErrorAction stop -WhatIf | Out-Null
I also tried to use $WhatIfPreference as in this StackOverflow answer, which had the same result.