title: Passing through -Verbose status to module cmdlets
body: <p>I have a PowerShell module that encapsulates a number of commonly-used business functions. It's not generally called from the console; rather, its functions are called by automated deployment and management scripts that import the module.</p>
  
  <p>The module incorporates a logging function that writes to both a centralised logging location. I'd also like to hook into the <a href="https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/write-verbose" rel="noreferrer">Write-Verbose</a> functionality to write to the console as well.</p>
  
  <pre><code>#'Start Script.ps1
  #'----------------
  
  Import-Module Corporate
  Write-Logger 'Foo'
  </code></pre>
  
  <p>My restriction is that - from within the Corporate PowerShell module - I need to determine whether Script.ps1 has been called with the <code>-Verbose</code> parameter. Ideally, I would like the determination code entirely within the module itself.</p>
  
  <p>Here's an example:</p>
  
  <pre><code>[CmdletBinding()]
  Param ()
  
  New-Module -Name TempModule -ScriptBlock {
      function Test-ModuleVerbose() {
          [CmdletBinding()]
          Param ()
  
          PROCESS {
              $vb = ($PSCmdlet.MyInvocation.BoundParameters['Verbose'] -eq $true)
              Write-Host ("1: Module verbose preference: " + ($PSCmdlet.MyInvocation.BoundParameters['Verbose'] -eq $true))
              Write-Host ("2: Module verbose preference: " + $Script:VerbosePreference)
              Write-Host ("3: Module verbose preference: " + $VerbosePreference)
          }
      }
  } | Out-Null
  
  function Test-Verbose() {
      [CmdletBinding()]
      Param ()
  
      PROCESS {
          Write-Host ("Verbose preference: $VerbosePreference")
          Test-ModuleVerbose
      }
  }
  
  Test-Verbose
  </code></pre>
  
  <p>Save the above as <strong>test.ps1</strong>. When invoked from the console:</p>
  
  <pre><code>PS C:\temp&gt; .\test.ps1
  Verbose preference: SilentlyContinue
  1: Module verbose preference: False
  2: Module verbose preference:
  3: Module verbose preference: SilentlyContinue
  
  PS C:\temp&gt; .\test.ps1 -Verbose
  VERBOSE: Exporting function 'Test-ModuleVerbose'.
  VERBOSE: Importing function 'Test-ModuleVerbose'.
  Verbose preference: Continue
  1: Module verbose preference: False
  2: Module verbose preference:
  3: Module verbose preference: SilentlyContinue
  </code></pre>
  
  <p>As you can see, the $VerbosePreference variable is not available from within the module. Is there a way of picking up from within the module whether the calling script has been invoked with the <code>-Verbose</code> flag?</p>