Author Posts

April 14, 2016 at 2:20 pm

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?

April 14, 2016 at 2:26 pm

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

April 14, 2016 at 3:08 pm

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

April 14, 2016 at 4:46 pm

'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'.)

April 15, 2016 at 7:32 am

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;}

April 15, 2016 at 12:02 pm

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.

April 15, 2016 at 2:39 pm

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!