Get NT style domain\user given DN

醉酒当歌 提交于 2019-12-11 02:24:45

问题


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


回答1:


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.




回答2:


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?




回答3:


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.



来源:https://stackoverflow.com/questions/1796426/get-nt-style-domain-user-given-dn

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!