Need help on where-object in powershell

Viewed 29

if I execute the below code it is not filtering, it is returning all the results.

enter image description here

$R datatype is below enter image description here

1 Answers

{} 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)}
Related