Reputation: 4239
I want to get DirectoryEntry
object for e.g. Domain-Users group. I'm following this link to remove user from a certain group.
strGroup = "CN=TestGroup,OU=TestOU";
objGroup = objADAM.Children.Find(strGroup, "group");
This code is from MSDN example. If I find my group in Active Directory Users and Computers applet, which is CN and OU?
EDIT:
To be more general, where do I find this name for Find
method?
From MSDN:
name
Type: System.String
The name of the child directory object for which to search.
Is this the distinguished name or else?
Upvotes: 2
Views: 3744
Reputation: 1626
You are mixing two separate environments that share a significant amount of overlap. DirectoryEntry is part of the DirectoryServices package, GetObject is a VBA tool that interfaces with ActiveDs.dll.
If this needs to be visual basic script then you have the equivalent of a DirectoryEntry from GetObject() or the Find() method. If you need access to properties use the object.Get("property_name") method (returns an array for multivalued attributes)
If you can swap development platform to something .NET, you'll have access to all the DirectoryServices you want.
EDIT: If this is a C# .NET app, here's the code to use
private static DirectoryEntry getGroupDE(String group)
{
String adserver = "dc.companyname.com";
String searchroot = "ou=Groups,dc=companyname,dc=com";
DirectorySearcher ds = new DirectorySearcher();
ds.SearchRoot = new DirectoryEntry(String.Format("LDAP://{0}/{1}",adserver,searchroot));
ds.SearchScope = SearchScope.Subtree;
ds.Filter = String.Format("(&(objectCategory=group)(sAMAccountName={0}))",group);
SearchResult sr = ds.FindOne();
if (sr == null)
{
return null;
}
return sr.GetDirectoryEntry();
}
Upvotes: 2