Data Stream Best Practices

Welcome Forums General PowerShell Q&A Data Stream Best Practices

This topic contains 1 reply, has 2 voices, and was last updated by

6 months, 2 weeks ago.

  • Author
  • #113620

    Topics: 8
    Replies: 15
    Points: 17
    Rank: Member

    What are the best practices when it comes to Write-Verbose where you also have Write-Warning and Write-Error? Should I log all messages in the Verbose stream even if I already presented it to the user in a different stream?

    For example, if I am starting a file copy, I might state that in verbose, but if a file already exists, I would write a warning for it. Would I put that same message into a verbose message in addition to the warning message? In other words, should I treat the verbose stream as a holistic stream of all events that occurred?

  • #113627

    Topics: 2
    Replies: 397
    Points: 689
    Helping Hand
    Rank: Major Contributor

    Verbose should, generally, list what's being attempted — and perhaps when the action has been successfully completed as well, if listing that is meaningful in context.

    Warnings should be emitted whenever a non-critical failure or potentially dangerous action has occurred.

    Depending on the situation, you may want to implement ShouldProcess to cover some of these scenarios. For example, if you need to overwrite a file that the user may not want to be overwritten, you can implement ShouldProcess in order to prompt the user when this might occur and ask them how to proceed.

The topic ‘Data Stream Best Practices’ is closed to new replies.

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