Skip to content

Null checking issue with Powershell 7 (rc3) #11957

@michaelsync

Description

@michaelsync

if condition checking for a null variable is incorrect in Powershell 7 (rc3)

Steps to reproduce

  • Run this code in Powershell 7(rc3)
$Body = $Body | ConvertTo-Json -Depth 10 -Compress
if ($Body) {
   Write-Host "I am not Null."
}
else{
   Write-Host "I am NULL." 
}


Expected behavior

It should show "I am NULL."

Actual behavior

It shows "I am not Null.".

Here is the screenshot. I run the same scripts in Powershell 7 (rc3), Powershell 6 and Powershell 5. It works correctly in PS5 and 6 but not in PS7rc3.

image

Environment data

Name                           Value
----                           -----
PSVersion                      7.0.0-rc.3
PSEdition                      Core
GitCommitId                    7.0.0-rc.3
OS                             Microsoft Windows 10.0.18363
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
```

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-AnsweredThe question is answered.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions