I am trying to use the DirectorySearcher from .Net to query for disabled users.
I am using a fairly fast list function very similar to the one posted here.
Enumerating Large Groups With Active Directory.
I have tried changing the filter to
(&(objectCategory=person)(userAccountControl:1.2.840.113556.1.4.803:=2))
I get no results. It seems that I cannot use the DirectorySearcher in this manor. Has anyone done anything like this. I just need basic info and would prefer a lightweight/fast query.
Using the
System.DirectoryServices.AccountManagementnamespace, introduced in .NET 3.5, things like that become a lot easier.Read all about it here: Managing Directory Security Principals in the .NET Framework 3.5
You would first have to establish a context for your operations – AD LDS is explicitly supported:
and then you’d create a
PrincipalSearcherand define in a “query-by-example” style what you’re looking for:Pretty nifty, eh?? If you ever can – use the new
S.DS.AMnamespace!!