none
Can I count on count? RRS feed

  • Question

  • If I run the following PS script, it provides me $null as the count of a variable that counts 1 object. What can be in the background?

    $result=@()
    $line="" |select prop1,prop2
    $line.prop1="apple"
    $line.prop2=2
    $result+=$line
    $line="" |select prop1,prop2
    $line.prop1="apple"
    $line.prop2=3
    $result+=$line
    $line="" |select prop1,prop2
    $line.prop1="pear"
    $line.prop2=4
    $result+=$line
    "
    Filled. Current value:"
    $result

    "
    Make a few check:
    "
    '($result | where {$_.prop1 -eq "apple"}).count value: '+($result | where {$_.prop1 -eq "apple"}).count
    'This is the problematic line: ($result | where {$_.prop1 -eq "pear"}).count value:'+($result | where {$_.prop1 -eq "pear"}).count
    'This is the problematic line: ($result | where {$_.prop1 -eq "pear"}).count -eq $null value: '+(($result | where {$_.prop1 -eq "pear"}).count -eq $null)

    '($result | where {$_.prop1 -eq "apple"}).prop1.count value:'+($result | where {$_.prop1 -eq "apple"}).prop1.count
    '($result | where {$_.prop1 -eq "pear"}).prop1.count value:'+($result | where {$_.prop1 -eq "pear"}).prop1.count

    Tuesday, February 4, 2020 4:23 PM

All replies