I need your help in getting the CN/DN if the last part of the OU name is provided. For ex In our Active Directory domain of xyz.org which has OU of
Accounts, sub OU Users and another Sub OU
Managers (xyz.org>Accounts>Users>Managers)
Here If I provide Managers as an Input, it has to output the CN:
xyz.org/Accounts/Users/Managers
Something like below:
DirectoryEntry dirEntry = new DirectoryEntry("LDAP://xyz.org");
DirectorySearcher ds = new DirectorySearcher(dirEntry);
string objectName = "Managers";
ds.Filter = "(&(objectClass=organizationalUnit)(OUName(Notacorrect)=" + objectName + "))";
try
{
if (ds.FindOne() != null)
{
//Get the DN or CN name as said
}
}
catch
{
}
ashiqf
Participant
868 Points
397 Posts
How to Get the Canonical/Distinguished Name of a OU
Feb 05, 2013 02:00 PM|LINK
Hi All,
I need your help in getting the CN/DN if the last part of the OU name is provided. For ex In our Active Directory domain of xyz.org which has OU of Accounts, sub OU Users and another Sub OU Managers (xyz.org>Accounts>Users>Managers)
Here If I provide Managers as an Input, it has to output the CN:
xyz.org/Accounts/Users/Managers
Something like below:
DirectoryEntry dirEntry = new DirectoryEntry("LDAP://xyz.org"); DirectorySearcher ds = new DirectorySearcher(dirEntry); string objectName = "Managers"; ds.Filter = "(&(objectClass=organizationalUnit)(OUName(Notacorrect)=" + objectName + "))"; try { if (ds.FindOne() != null) { //Get the DN or CN name as said } } catch { }Please help
Ashiq
ashiqf
Participant
868 Points
397 Posts
Re: How to Get the Canonical/Distinguished Name of a OU
Feb 05, 2013 02:31 PM|LINK
DirectoryEntry dirEntry = new DirectoryEntry("LDAP://xyz.org"); DirectorySearcher ds = new DirectorySearcher(dirEntry); ds.SearchScope = SearchScope.Subtree; string objectName = "Managers"; ds.PropertiesToLoad.Add("cn"); ds.Filter = "(&(objectClass=organizationalUnit)(ou=" + objectName + "))"; if (ds.FindOne() != null) { SearchResult deResult = ds.FindOne(); string ouName = deResult.Properties["cn"][0].ToString(); }I get an exception message. Index was out of range on string ouName = deResult.Properties["cn"][0].ToString();
Please help
Ashiq
ashiqf
Participant
868 Points
397 Posts
Re: How to Get the Canonical/Distinguished Name of a OU
Feb 06, 2013 03:44 AM|LINK
Any help here...
Ashiq