If the array has only one CustomObjects and the Count property is null. Why?
If use only strings, the Count property is one.
function MyFunction
{
$Objects = @()
$Objects += [pscustomobject]@{Label = "Hallo"}
# $Objects += [pscustomobject]@{Label = "World"}
$Objects
}
$objs = MyFunction
Write-Host "Count: $($objs.Count)"
Output: "Count: "
because $objs.Count
is null
function MyFunction
{
$Objects = @()
$Objects += [pscustomobject]@{Label = "Hallo"}
$Objects += [pscustomobject]@{Label = "World"}
$Objects
}
$objs = MyFunction
Write-Host "Count: $($objs.Count)"
Output: "Count: 2"
Behavior is different if I add strings
function MyFunction
{
$Objects = @()
$Objects += "Hallo"
# $Objects += [pscustomobject]@{Label = "World"}
$Objects
}
$objs = MyFunction
Write-Host "Count: $($objs.Count)"
Output: "Count: 1"