G
golliz
Hi all!
I'm new to Active Directory and the interoperability with the framework.
I'm working with Active Directory and c# with the new framework 3.5 and the
System.DirectoryServices.AccountManagement library and PrincipalSearcher
class to search in the AD tree.
I must retrieve the "CanonicalName", DistinguishedName and SID.
I'm using this code:
public List<UserPrincipal> GetAllGroups(string uName, string pwd)
{
List<UserPrincipal> retVal = null;
//Create a context for the search take place in
using (PrincipalContext context = new PrincipalContext(ContextType.Domain
, "domainController", "OU=*****,OU=****,DC=****,DC=****"
, ContextOptions.Negotiate, uName, pwd))
{
//Create a group principal filter with the context
using (UserPrincipal filter = new UserPrincipal(context))
{
//Create a principal search using the filter
using (PrincipalSearcher searcher = new PrincipalSearcher())
{
retVal = (from principal in searcher.FindAll()
select principal as UserPrincipal).ToList();
foreach (UserPrincipal user in retVal) {
System.Security.Principal.SecurityIdentifier sid
= user.Sid;
string soj = user.StructuralObjectClass;
string upn = user.UserPrincipalName;
string name = user.Name;
string dsn = user.DistinguishedName;
}
}
}
}
return retVal;
}
It's all ok for DistinguishedName and SID but I Can't find the Attribute
"CanonicalName" in my UsersPrincipal and I dont know how can i resolve it.
Any help is welcome.
Thanks so mutch bye.
I'm new to Active Directory and the interoperability with the framework.
I'm working with Active Directory and c# with the new framework 3.5 and the
System.DirectoryServices.AccountManagement library and PrincipalSearcher
class to search in the AD tree.
I must retrieve the "CanonicalName", DistinguishedName and SID.
I'm using this code:
public List<UserPrincipal> GetAllGroups(string uName, string pwd)
{
List<UserPrincipal> retVal = null;
//Create a context for the search take place in
using (PrincipalContext context = new PrincipalContext(ContextType.Domain
, "domainController", "OU=*****,OU=****,DC=****,DC=****"
, ContextOptions.Negotiate, uName, pwd))
{
//Create a group principal filter with the context
using (UserPrincipal filter = new UserPrincipal(context))
{
//Create a principal search using the filter
using (PrincipalSearcher searcher = new PrincipalSearcher())
{
retVal = (from principal in searcher.FindAll()
select principal as UserPrincipal).ToList();
foreach (UserPrincipal user in retVal) {
System.Security.Principal.SecurityIdentifier sid
= user.Sid;
string soj = user.StructuralObjectClass;
string upn = user.UserPrincipalName;
string name = user.Name;
string dsn = user.DistinguishedName;
}
}
}
}
return retVal;
}
It's all ok for DistinguishedName and SID but I Can't find the Attribute
"CanonicalName" in my UsersPrincipal and I dont know how can i resolve it.
Any help is welcome.
Thanks so mutch bye.