Please tell me that I have a subtle error in my code and that this is actually not how Powershell works.
$in = "" if ($in -ne $null) { switch ($in) { $null { echo "This is impossible" } default { echo "out here!" } } }
All good, honest logic says that this script should never print " This is impossible ." But this is so if $ in is an empty string. Thus, in Powershell, it appears that an empty string and a null string are considered equivalent in a switch , but not in an if . This is so confusing and is one of the main reasons many people shy away from using Powershell.
Can someone enlighten me why this is so? Does anyone know what the switch really does behind the scenes? This, of course, does not make a direct comparison.
source share