User Listing from AD

  • Thread starter Thread starter Jason
  • Start date Start date
J

Jason

I need to get a listing of users from Active Directory. Getting the list is
no problem using the DirectorySearcher class. My problem is getting the full
legacy-style domain name of the user (in the form of domain\username). The
"sAMAccountName" property only gives me the username portion. What property
gives with the domain? Or do I need to be looking at a different AD object
altogether?

Thanks,
Jason
 
I need to get a listing of users from Active Directory. Getting the list is
no problem using the DirectorySearcher class. My problem is getting the full
legacy-style domain name of the user (in the form of domain\username). The
"sAMAccountName" property only gives me the username portion. What property
gives with the domain? Or do I need to be looking at a different AD object
altogether?

You can't get that from a user object - you'd have to go inspect the
"domainDNS" object that this user (or those users) are contained
under.

E.g. you'd have to walk up the AD object tree (by looking at the
DirectoryEntry.Parent property repeatedly) and go find the object of
class "domainDNS" - it will contain an attribute called "name" which
is the NetBIOS style name of the domain.

MArc

================================================================
Marc Scheuner May The Source Be With You!
Berne, Switzerland m.scheuner -at- inova.ch
 
Thanks Marc for the info.

Looks like I need to look at the instanceType field that specifies that
object type? (In this case the value 5 indicates domainDNS) Or should I be
looking at something else?

- Jason
 
Looks like I need to look at the instanceType field that specifies that
object type? (In this case the value 5 indicates domainDNS) Or should I be
looking at something else?

Yes - why not look at the "DirectoryEntry.SchemaClassName" property??

It will contain the schema class name, e.g. "user" for users,
"domainDNS" for domains, "group" for groups and so on.

Marc

================================================================
Marc Scheuner May The Source Be With You!
Berne, Switzerland m.scheuner -at- inova.ch
 
Back
Top