Where-Object not filtering correctly

I put together this one liner trying to only see where ProtectedFromAccidentalDeletion is FALSE:

Get-ADOrganizationalUnit -Filter * -Properties ProtectedFromAccidentalDeletion | Where-Object {$_.ProtectedFromAccidentalDeletion -eq ‘FALSE’}

but I still see only OU’s that have property = TRUE

What am I missing?

Get-ADOrganizationalUnit -Filter * -Properties ProtectedFromAccidentalDeletion | Where-Object {$_.ProtectedFromAccidentalDeletion -eq $false}

Ah great thanks AK. Can you briefly explain that character for my edification please? I don’t recall reading about it in Month of Lunches

‘False’ is a string, $false is a boolean. (The $ character, in this context, indicates a variable named false.)

The way the -eq (and other comparison operators) work is that if the two types aren’t the same, PowerShell will try to convert the value on the right to the same type as the value on the left. (In this case, it’ll try to convert a string into a boolean).

When it comes to strings, empty strings are treated as $false, and any non-empty string becomes $true. So, while it may look odd:

$true -eq 'False'

Will report True, because ‘False’ is a non-empty string.

In the other direction:

'False' -eq $true

This will be false, because now the boolean $true is being converted into a string (which happens to just be the word ‘True’.)

The only thing I’d mention is, if you pipe OU object to get-member, you’ll see that ProtectedFromAccidentalDeletion property is boolean, not string, hence $true or $false when comparing values of that property:

ProtectedFromAccidentalDeletion Property System.Boolean ProtectedFromAccidentalDeletion {get;set;}

Dave, got a bit lost on the examples but I appreciate the background and this will probably get clearer with more experience.

AK I did see that and now in context, I have the background for the understanding. thanks.

I have to laugh. I wrote “I don’t recall reading about it in Month of Lunches” and of course, I’m reading the last chapter today and there it is pg 299!