WhatIf Output

Welcome Forums General PowerShell Q&A WhatIf Output

This topic contains 4 replies, has 3 voices, and was last updated by

7 months, 1 week ago.

  • Author
  • #108490

    Points: 0
    Rank: Member

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

  • #108500

    Points: 632
    Helping Hand
    Rank: Major Contributor

    -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?

  • #108505

    Points: 0
    Rank: Member

    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.

  • #108511

    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

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

  • #108512

    Points: 0
    Rank: Member

    Thanks Don!

The topic ‘WhatIf Output’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort