Search PowerShellers and other PowerShell-related sites

Tuesday, August 12, 2008

"LDAP query" versus "WHERE"

Here is the good example for Jeffrey Snover's post "When NOT To Use "WHERE"". This is original Andrey Moiseev's one-liner to get a list of all computed attributes in AD, mentioned in Dmitry Sotnikov's post "List all Constructed Attributes"

Get-QADObject -SearchRoot "CN=Schema,CN=Configuration,dc=MyDomain,dc=COM" -Type attributeSchema -IncludedProperties systemFlags -SizeLimit 0 | where {$_.SystemFlags -band 4}


This one-liner needs 120 seconds to complete on my system.

Let's try the same thing, but this time with LDAP query:

Get-QADObject -SearchRoot "CN=Schema,CN=Configuration,dc=MyDomain,dc=COM" -ldapfilter '(systemFlags:1.2.840.113556.1.4.803:=4)' -Type attributeSchema -IncludedProperties systemFlags -SizeLimit 0


I can see a list of all computed attributes in AD in just 3 seconds.

1 comment:

Dmitry Sotnikov said...

Very cool!