|
security
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How do I filter an Active Directory search to an OU (organizational unit)?I need to be able to retrieve a list of the users in an OU. The following C# code works just fine and dumps out a list of all of the user objects in all OUs in our active directory. I have not been able to figure out the filtering syntax to get this to just display the users in an OU. If anybody has any suggestions I'd be very appreciative. I've searched the online help, web, and news groups. I must not be understanding some fundamental concept here because nothing I have tried has worked. using System; using System.DirectoryServices; namespace ADSearch { public class ADRead { static void Main(string[] args) { DirectoryEntry entry = new DirectoryEntry ("LDAP://jrcc.local"); DirectorySearcher searcher = new DirectorySearcher(entry); searcher.Filter = "(&(objectClass=user)(objectCategory=person))"; SearchResultCollection rc = searcher.FindAll(); for(int i=0; i<rc.Count; i++) { Console.WriteLine(rc[i].Path); } Console.WriteLine("Users Found: " + rc.Count.ToString()); } } } Thanks, John Answered on other newsgroup. Please try not to multi-post.
Joe K. Show quoteHide quote "JohnH." <j***@jrcc.net> wrote in message news:1113420053.573364.223360@l41g2000cwc.googlegroups.com... > Hi, > > I need to be able to retrieve a list of the users in an OU. The > following C# code works just fine and dumps out a list of all of the > user objects in all OUs in our active directory. I have not been able > to figure out the filtering syntax to get this to just display the > users in an OU. If anybody has any suggestions I'd be very > appreciative. I've searched the online help, web, and news groups. > I must not be understanding some fundamental concept here because > nothing I have tried has worked. > > using System; > using System.DirectoryServices; > > namespace ADSearch > { public class ADRead > { > static void Main(string[] args) > { > DirectoryEntry entry = new DirectoryEntry > ("LDAP://jrcc.local"); > DirectorySearcher searcher = new DirectorySearcher(entry); > searcher.Filter = "(&(objectClass=user)(objectCategory=person))"; > > SearchResultCollection rc = searcher.FindAll(); > for(int i=0; i<rc.Count; i++) > { > Console.WriteLine(rc[i].Path); > } > Console.WriteLine("Users Found: " + rc.Count.ToString()); > } > } > } > > Thanks, > John > "Joe Kaplan (MVP - ADSI)" <joseph.e.kap***@removethis.accenture.com> wrote What was the other newsgroup?in message news:%23OI5mBGQFHA.580@TK2MSFTNGP15.phx.gbl... > Answered on other newsgroup. microsoft.public.adsi.general
Unfortunately, there is no newsgroup specific to .NET Directory Services programming, so they tend to get scattered around to lots of different groups. This one is common, but the adsi.general group gets the most traffic. Your answer was really similar to mine FWIW. :) Joe K. Show quoteHide quote "Jeff Connelly" <nom***@thank.you> wrote in message news:e3Kbt0GQFHA.904@tk2msftngp13.phx.gbl... > > "Joe Kaplan (MVP - ADSI)" <joseph.e.kap***@removethis.accenture.com> wrote > in message news:%23OI5mBGQFHA.580@TK2MSFTNGP15.phx.gbl... >> Answered on other newsgroup. > > What was the other newsgroup? > "Joe Kaplan (MVP - ADSI)" <joseph.e.kap***@removethis.accenture.com> wrote That is what I was actually curious about :-) Thanks.in message news:%23TAKftIQFHA.1500@TK2MSFTNGP09.phx.gbl... > > Your answer was really similar to mine FWIW. :)
Show quote
Hide quote
"JohnH." <j***@jrcc.net> wrote in message I think the easiest thing to do here would be to refine your LDAP string. news:1113420053.573364.223360@l41g2000cwc.googlegroups.com... > Hi, > > I need to be able to retrieve a list of the users in an OU. The > following C# code works just fine and dumps out a list of all of the > user objects in all OUs in our active directory. I have not been able > to figure out the filtering syntax to get this to just display the > users in an OU. If anybody has any suggestions I'd be very > appreciative. I've searched the online help, web, and news groups. > I must not be understanding some fundamental concept here because > nothing I have tried has worked. > > using System; > using System.DirectoryServices; > > namespace ADSearch > { public class ADRead > { > static void Main(string[] args) > { > DirectoryEntry entry = new DirectoryEntry > ("LDAP://jrcc.local"); (LDAP syntax is confusing because several different looking syntaxes are allowed - it's not consistent. I'll show you one syntax that should work - there are others.) Let's say you had on the jrcc.local domain an OU called MyBusiness (common), and then below that an OU called Users. You would use LDAP://OU=Users,OU=MyBusiness,DC=jrcc,DC=local That sets your LDAP path to point to that node, your filter does the rest of the work. Although you might find you don't need your filter anymore.
Running a program with elevated priveleges
Cannot open log for source {0}. You may not have write access. (Access right wanish after a while) local admin security question Rijndael decryption succeeds SOMETIMES Getting user ID from Web Service credentials Access to the path is denied: Assembly Permission Problem Using HttpContext from a web server? ISO/IEC 9797-1 MAC Algorithm 3 how to? RSACryptoServiceProvider usage question Parsing X.509 Digital Certificate newbie question |
|||||||||||||||||||||||