2

Currently trying to use the following to pull a list of servers that are not disabled.

$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objsearcher.Filter = "(&(OperatingSystem=Window*Server*)(Enabled -eq $true))"

My issue is that this is not a valid search filter.

I've done alot of searching, and cannot find a way to filter for whether a device is enabled or disabled, like I'm attempting to above.

I'm aware that I should be able to do it via:

Get-ADComputer -Filter 'Enabled -eq $true' 

But was hoping to avoid this.

1 Answer 1

1

I found this:

$objsearcher.Filter = "(&(OperatingSystem=Window*Server*)(!useraccountcontrol:1.2.840.113556.1.4.803:=2))"

If you wanted to search for disabled instead, remove the ! operator:

$objsearcher.Filter = "(&(OperatingSystem=Window*Server*)(useraccountcontrol:1.2.840.113556.1.4.803:=2))"
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks mate that solved it :) out of curiosity, if I wanted to invert it to only search for disabled any idea how I'd achieve that ?
See my edit and also have a look at the source in the link.

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.