User Listing from AD

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
 
M

Marc Scheuner [MVP ADSI]

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
 
J

Jason

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
 
M

Marc Scheuner [MVP ADSI]

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top