简体   繁体   中英

Search for a specific group in AD with a part of the CN name

In the AD, there is a list of groups such as:

  • ServerDEV_4283V
  • ServerDEV_4221C
  • ServerDEV_9080M
  • ServerDEV_2722W

....

I am able to get one specific group but I can't get a list of groups with starting with ServerDEV_4.

Here is my code block:

    DirectoryEntry entry = new DirectoryEntry("LDAP://YourServer/OU=SubOU,OU=TopLevelOU,dc=test,dc=com", userName, password,AuthenticationTypes.Secure);

try
{     
     DirectoryEntry childGroup = entry.Children.Find("CN=ServerDEV-4283V");
     // create group here
}
catch (DirectoryServicesCOMException exception)
{
    // handle the "child not found" case here ...
}

Is there a way I could do the RegEx like "ServerDEV-4" so I can get 2 top groups?

Appreciate your help.

Thanks

It turned out the wildcard would be enough.

        DirectoryEntry entry = new DirectoryEntry("LDAP://YourServer/OU=SubOU,OU=TopLevelOU,dc=test,dc=com", userName, password,AuthenticationTypes.Secure);

try
{     
     DirectoryEntry childGroup = entry.Children.Find("CN=ServerDEV-4*");
     // create group here
}
catch (DirectoryServicesCOMException exception)
{
    // handle the "child not found" case here ...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM