Reputation: 79
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.
Upvotes: 2
Views: 84
Reputation: 17104
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))"
Upvotes: 1