2

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
  • 4
    As tip for future questions: don't add images of code in the question. Instead add the code as Formatted text Commented Nov 16, 2020 at 9:52

1 Answer 1

2

{} 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)}
Sign up to request clarification or add additional context in comments.

2 Comments

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)}
@Hussain That's great! Please consider marking the answer "accepted" by clicking the checkmark on the left

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.