0
Search-ADAccount -AccountInactive -ComputersOnly -TimeSpan 359.00:00:00 -Searchbase "OU=Disabled Computers,DC=mydomain,DC=net"

When filtering the previous script with Where {$_.enabled -eq 'false'} I get no results.

But when filtering with Where {$_.enabled -ne 'true'} I get the expected results.

Anyone know why this would be??

2
  • can you confirm that the .enabled property equals false? Commented Feb 7, 2017 at 18:12
  • Yes the property equals false Commented Feb 9, 2017 at 19:17

1 Answer 1

1

This is because the enabled property isn't the string False. But is a Boolean value that gets formatted as a string when displayed. For example, if you evaluate $false you'll receive back what looks like the string False. But if you evaluate $False | Get-Member you will see that TypeName: System.Boolean

That means that you should compare to $False rather than "False"

$InactiveComputers = Search-ADAccount -AccountInactive -ComputersOnly -TimeSpan 359.00:00:00 -Searchbase "OU=Disabled Computers,DC=mydomain,DC=net"
#Displaying that enabled property is System.Boolean
$InactiveComputers[0].enabled | Get-Member
$InactiveComputers | Where {$_.enabled -eq $False}

Edit:

Alternatively, by switching the order of the compare you can dynamically cast $False to the string. This is the difference between "False" -eq $False and $False -eq "False"

$InactiveComputers = Search-ADAccount -AccountInactive -ComputersOnly -TimeSpan 359.00:00:00 -Searchbase "OU=Disabled Computers,DC=mydomain,DC=net"
$InactiveComputers | Where {"False" -eq $_.enabled}
Sign up to request clarification or add additional context in comments.

3 Comments

That was it. Thank you very much
If an answer worked for you, it is best practice to accept it.
I tried to upvote it and can't because I'm below 15. I thought that applied to accepting it as well.

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.