Hi,
I have the DN of a user in Active Directory, I want to get the "NT style" domain\user from this. The sAMAccountname AD property gives me the user part, but what about the domain?
Thanks
Hi,
I have the DN of a user in Active Directory, I want to get the "NT style" domain\user from this. The sAMAccountname AD property gives me the user part, but what about the domain?
Thanks
How about using --> System.Security.Principal.NTAccount.ToString()
See msdn info about it here: NTAccount.ToString()
This should return a string in the format of domain\user... is this what you are after?
You can get it by taking the last part of the user DN (DC=domain,DC=local
) and adding CN=Partitions,CN=Configuration,
before.
Then do a subtree search for (&(nCName="DC=domain,DC=local")(nETBIOSName=*))
with CN=Partitions, CN=Configuration, DC=domain, DC=local
as the starting point; the entry you get back will have the NETBIOS name of the domain in the nETBIOSName
-attribute.
The easiest way to do this conversion is through the DsCrackNames API. You specify the input format and output format and it does the conversion for you.