title: Powershell treats empty string as equivalent to null in switch statements but not if statements
body: <p>Please tell me that I've got a subtle mistake in my code here and that this is not actually the way that Powershell operates.</p>
  
  <pre><code>$in = ""
  
  if ($in -ne $null)
  {
      switch ($in)
      {
          $null { echo "This is impossible" }
          default { echo "out here!"  }
      }
  }
  </code></pre>
  
  <p>All good, honest logic says that this script should never print out "<strong>This is impossible</strong>". But it does, if $in is an empty string. So in Powershell it would appear that an empty string and a <code>null</code> string are considered equivalent <em>in a <code>switch</code> statement but not in an <code>if</code> statement</em>. This is <em>so</em> confusing and is one of the main reasons many people shy away from using Powershell.</p>
  
  <p>Can anyone enlighten me as to why this is the case? Does anyone know what switch is actually doing behind the scenes? It's certainly not doing a straight -eq comparison.</p>