title: Pass through user parameter and fallback to default
body: <p>How do I fallback to default value inside a subroutine? Consider having <code>1.ps1</code> as follows:</p>
  <pre><code>param(
      [Parameter(Mandatory)]
      [ValidateNotNullOrEmpty()]
      [ValidateSet('A', 'B')]
      [String]
      $What,
  
      $Target
  )
  
  function CallA {
     param(
         $Target = 'default for A'
     )
  
     Write-Host $Target
  }
  
  function CallB {
     param(
         $Target = 'default for B'
     )
  
     Write-Host $Target
  }
  
  &amp;&quot;Call$What&quot; -Target $Target
  </code></pre>
  <p>If I call it from powershell console like so: <code>./1 -What A</code> I'll get empty line, whereas the intention would be to get <code>default for A</code> as the result.</p>
  <p>I could of course check if <code>$Target</code> is <code>$null</code> in each function but I find this way being cumbersome. Is there a better way except for explicit check?</p>