title: Passing null to a mandatory parameter to a function
body: <p>Effectively my problem comes down to this:</p>
  
  <p>I can't have a function with a mandatory parameter and pass $null to that parameter:</p>
  
  <pre><code>Function Foo
  {
      Param
      (
          [Parameter(Mandatory = $true)][string] $Bar
      )
  
      Write-Host $Bar
  }
  
  Foo -Bar $null
  </code></pre>
  
  <p>This returns <code>foo : Cannot bind argument to parameter 'Bar' because it is an empty string.</code></p>
  
  <p>Likewise, making it an array also fails:</p>
  
  <pre><code>Function Foo
  {
      Param
      (
          [Parameter(Mandatory = $true)][string[]] $Bar
      )
  
      Write-Host $Bar
  }
  
  Foo -Bar 1, 2 
  
  &gt; 1 2
  
  Foo -Bar 1, 2, $null
  
  &gt; foo : Cannot bind argument to parameter 'Bar' because it is an empty string.
  </code></pre>
  
  <p>In programming terms it is entirely possible to have a function that accepts a mandatory nullable parameter, but I can't find a way of doing that in PowerShell.</p>
  
  <p>How do I do it?</p>