Author Posts

August 14, 2018 at 5:44 pm

Does anyone know what stream -WhatIf messages write to? Does it skip all streams and write to host?

August 14, 2018 at 6:12 pm

-WhatIf is just writing to StdOut. I would say it's comparable to Write-Host from a behavior standpoint. Why or What exactly are you trying to figure out?

August 14, 2018 at 6:29 pm

I am using -WhatIf to aid in a pester test. I have tested the portion of code that executes the state change that the tool is accomplishing, but when testing different parameters that sets up the execution of that code, I don't need to rerun it. So I use -WhatIf to skip it. The problem is that I want to hide the WhatIf message because it makes the pester output a little muddy. Piping a "WhatIf Producing" command to Out-Null doesn't work, which makes me think that it doesn't write to Stream 1. After some further testing, I find that it doesn't go away with anything that I do such as redirecting it to a file, nullifying it, or redirecting all streams to std out then nullifying it.

(Stop-Process -Name Notepad *>&1) | Out-Null

 

I am referencing about_redirection for stream data to assist in troubleshooting. The only thing I can come up with is that to writes directly to host.

August 14, 2018 at 6:33 pm

The “correct” approach would probably be to mock the command. But -WhatIf uses the host, not one of the pipelines.