DbNull Treatment in PoSh 2 vs. 3

PoSh v3 apparently interprets System.DbNull values differently than PoSh v2.

In v2, this expression returns True: [System.DbNull]::Value -eq $null. In v3, it returns False.

More specifically, in v3 ([System.DbNull]::Value).Length returns 1, whereas in v2 it returns $null.

Has anybody else seen this?

May 31st, 2013 4:47pm

Hi,

I tried below command on V2 and V3, the result is the same:

[System.DbNull]::Value -eq $null 

The result is  False

The below command on V2 and V3, also the same result with a new line[System.DbNull]::Value

Only the below command is not same:

([System.DbNull]::Value).Length 

Regards,

Yan Li

If you have any feedback on our support, please click here .

Free Windows Admin Tool Kit Click here and download it now
June 3rd, 2013 9:06am

Hi,

Just checking in to see if the suggestions were helpful. Please let us know if you would like further assistance.

 

If you have any feedback on our support, please click here .

June 5th, 2013 4:52am

Thank you for the reply. It was helpful and I apologize for the belated follow-up. Yes, I do get the same results when testing equality against $null in v2 and v3. My earlier test must have been messed up.

But the .Length test results do differ, as you found too. Is there any explanation for this? I'm mostly just curious because it is easy enough to code around the discrepancy between v2 and v3. Using a .Length check to test for nulls is not the best coding practice anyway.

Free Windows Admin Tool Kit Click here and download it now
July 1st, 2013 7:58pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics