By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,304 Members | 3,132 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,304 IT Pros & Developers. It's quick & easy.

Active Directory Query issue

P: n/a
Hi,

I am trying to enumerate Exchange Admin groups, but fail to with the
folowing code. Can someone help me with this issue.
The executing user has sufficient permissions.

Expand|Select|Wrap|Line Numbers
  1. using System;
  2.  
  3. namespace Active_Directory
  4. {
  5. /// <summary>
  6. /// Summary description for Class1.
  7. /// </summary>
  8. class Class1
  9. {
  10. /// <summary>
  11. /// The main entry point for the application.
  12. /// </summary>
  13. [STAThread]
  14. static void Main(string[] args)
  15. {
  16. System.DirectoryServices.DirectoryEntry entry =
  17. new
  18. System.DirectoryServices.DirectoryEntry(@"LDAP://DC=<rootdomain>");
  19.  
  20. System.DirectoryServices.DirectorySearcher mySearcher = new
  21. System.DirectoryServices.DirectorySearcher(entry);
  22. mySearcher.Filter =
  23. "(&(objectClass=msExchAdminGroup)(objectCategory=ms-Exch-Admin-Group))";
  24. Console.WriteLine(mySearcher.FindAll().Count);
  25. }
  26. }
  27. }
  28.  
  29.  
Nov 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
You need to iterate through the result collection..

akin to

mySearcher.Filter =
"(&(objectClass=msExchAdminGroup)(objectCategory=m s-Exch-Admin-Group))";
foreach(System.DirectoryServices.SearchResult result in
mySearcher.FindAll())
{
Console.WriteLine( result.GetDirectoryEntry().Path );
}
Denis
"mpriem" <sp**@mpriem.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Hi,

I am trying to enumerate Exchange Admin groups, but fail to with the
folowing code. Can someone help me with this issue.
The executing user has sufficient permissions.

Expand|Select|Wrap|Line Numbers
  1.  using System;
  2.  namespace Active_Directory
  3.  {
  4.  /// <summary>
  5.  /// Summary description for Class1.
  6.  /// </summary>
  7.  class Class1
  8.  {
  9.  /// <summary>
  10.  /// The main entry point for the application.
  11.  /// </summary>
  12.  [STAThread]
  13.  static void Main(string[] args)
  14.  {
  15.  System.DirectoryServices.DirectoryEntry entry =
  16.  new
  17.  System.DirectoryServices.DirectoryEntry(@"LDAP://DC=<rootdomain>");
  18.  System.DirectoryServices.DirectorySearcher mySearcher = new
  19.  System.DirectoryServices.DirectorySearcher(entry);
  20.  mySearcher.Filter =
  21.  "(&(objectClass=msExchAdminGroup)(objectCategory=ms-Exch-Admin-Group))";
  22.  Console.WriteLine(mySearcher.FindAll().Count);
  23.  }
  24.  }
  25.  }
  26.  

Nov 17 '05 #2

P: n/a
>I am trying to enumerate Exchange Admin groups, but fail to with the
folowing code. Can someone help me with this issue. DirectoryEntry entry = new DirectoryEntry(@"LDAP://DC=<rootdomain>");


Can you spell out this LDAP path completely? What exactly is it? If
the DirEntry that you start off from is wrong, your search will never
work. You should try to use the "defaultNamingContext" from RootDSE
for your search, unless you have a clear reason NOT to use that as a
starting point.

--------------------------------
DirectoryEntry deRoot = new DirectoryEntry("LDAP://RootDSE");

string sDefaultNamingContext =
deRoot.Properties["defaultNamingContext"].Value.ToString();

DirectoryEntry entry = new DirectoryEntry("LDAP://" +
sDefaultNamingContext);

--------------------------------

Also, I've never successfully used the .Count property on the
collection returned by FindAll() - I'd just iterate over all the
entries to verify that you get anything back.

Marc
================================================== ==============
Marc Scheuner May The Source Be With You!
Berne, Switzerland m.scheuner -at- inova.ch
Nov 17 '05 #3

P: n/a
Thanks Guys,

It works now. Even the .Count property. I thinks I messed up the DN.

Regards,

Mark

--
Sent via .NET Newsgroups
http://www.dotnetnewsgroups.com
Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.