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

 
Participant
1 week, 6 days ago.

  • Author
    Posts
  • #113620

    Participant
    Points: 0
    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

    Participant
    Points: 19
    Rank: Member

    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.

You must be logged in to reply to this topic.