Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8672055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:06:22+00:00 2026-06-12T19:06:22+00:00

Please tell me that I’ve got a subtle mistake in my code here and

  • 0

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.

$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 out “This is impossible“. But it does, if $in is an empty string. So in Powershell it would appear that an empty string and a null string are considered equivalent in a switch statement but not in an if statement. This is so confusing and is one of the main reasons many people shy away from using Powershell.

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T19:06:23+00:00Added an answer on June 12, 2026 at 7:06 pm

    I think is a bug of powershell 2.0 (here some info on MSFT Connect).

    I can say that in v 3.0 you code return out here!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone please tell me what this means: 07-04 09:54:38.048: I/DetailActivity(15496): Title that is
Please tell me if I got this wrong. Anchor point is like a movable
please tell that can we consume .net web services in php or not. if
please tell that can we consume .net web services in php or not. if
Please tell me that the vs2008 has support for HTML5 or not? and also
Please tell me why my window doesn't render. Below is the javascript that i
Can anyone please tell me how I can write a bash shell script that
can someone please tell why , Great Microsoft that created C# language and now
Could somebody please explain or link to a resource that will tell me why
I did a search before asking so please don't tell me to do that.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.