if I execute the below code it is not filtering, it is returning all the results.
1 Answer
{} creates a [scriptblock] literal, the value of which will always evaluate to $True when cast to [bool].
Remove the {} around the comparisons inside the filter block:
$filteredRows = $R |Where-Object {$_.db_sync_state -eq 'NOT SYNCHRONIZING' -or -not $_.is_failover_ready}
As Gert Jan Kraaijeveld mentions, you can use () to group the individual comparisons if required:
$filteredRows = $R |Where-Object {($_.db_sync_state -eq 'NOT SYNCHRONIZING') -or (-not $_.is_failover_ready)}
2 Comments
Gert Jan Kraaijeveld
If you like to structure the filter (I personally do) you can use parentheses:
$filteredRows = $R |Where-Object {($_.db_sync_state -eq 'NOT SYNCHRONIZING') -or (-not $_.is_failover_ready)}Mathias R. Jessen
@Hussain That's great! Please consider marking the answer "accepted" by clicking the checkmark on the left

