0

Given an AD entry, how can I get the full qualified domain name of the user?

Up to now I used

((string)directoryEntry.Properties["userPrincipalName"].Value).Split('@')[1]

but userPrincipalName is not a required property, so I guess I need a fallback...

Alexander
  • 19,906
  • 19
  • 75
  • 162

1 Answers1

2

I believe that "cn" is a mandatory attribute in AD,and in my experience it has the same value as the login value, so you can try that. Im not 100% sure though, so try it and let met know, if not i will delete this answer.

Hopefully it helps.

Koen
  • 634
  • 3
  • 14
  • With my example user, `userPrincipalName` is `matslehmann@intra.contoso.com`, `cn` is `Mats Lehmann`, and I need the domain, which is `intra.contoso.com`. But thx for the try. – Alexander Oct 20 '14 at 13:57
  • Maybe the sAMAccountName? also mandatory. Take a look at this site for more attributes : http://www.kouti.com/tables/userattributes.htm – Koen Oct 20 '14 at 14:02