471,344 Members | 1,512 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,344 software developers and data experts.

User Listing from AD

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
Jul 21 '05 #1
3 1733
>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
Jul 21 '05 #2
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

"Marc Scheuner [MVP ADSI]" <m.********@inova.SPAMBEGONE.ch> wrote in message
news:6l********************************@4ax.com...
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

Jul 21 '05 #3
>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
Jul 21 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by David Jacques | last post: by
3 posts views Thread by Jason | last post: by
3 posts views Thread by =?Utf-8?B?ZG1idXNv?= | last post: by
reply views Thread by Ronak mishra | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.