I have an array of hashtables and I am trying to filter it to those who has a property value to true, but this what I am doing does not looks good.
# object looks like this
$array = @(
@{ Name = 'First'; Passed = $true }
@{ Name = 'Second'; Passed = $false }
)
function Filter {
Param($array)
$filtered = @()
foreach ($item in $array) {
if ($item.Passed = $true) {
$filtered += $item
}
}
return $filtered
}
Is there any other way I can get all elements who has property Passed = $True without the need to add those to another array.
$newarray = @($array | Where-Object { $_.Passed })$_.Passed -eq $true.