title: How does a cmdlet know when it really should call WriteVerbose()?
body: <p>How does a cmdlet know when it <em>really</em> should call <code>WriteVerbose()</code>,
  <code>WriteDebug()</code> and etc.?</p>
  
  <p>Perhaps I miss something simple but I cannot find the answer. All cmdlet
  implementations I have seen so far just call <code>WriteVerbose()</code> without any
  hesitation. I know that it is <em>correct</em> to do so, but it is not <em>effective</em>.</p>
  
  <p>Performance suffers when verbose mode is off but a cmdlet still prepares
  data for <code>WriteVerbose()</code> call, that is, for nothing.</p>
  
  <p>In other words, in a cmdlet I would like to be able to:</p>
  
  <pre><code>if (&lt;VerboseMode&gt;)
  {
      .... data preparation, sometimes expensive ...
      WriteVerbose(...);
  }
  </code></pre>
  
  <p>But I don't know how to get this <code>if (&lt;VerboseMode&gt;)</code>. Any ideas?</p>
  
  <hr>
  
  <p><strong>Conclusion:</strong>
  The @stej’s answer shows how get the required information in theory. In practice this is hacky and unlikely suitable. Thus, if a cmdlet produces really expensive verbose or debug output then it looks reasonable to introduce an additional parameter specifying verbosity levels.</p>