Can SQL pull user accounts from a domain server ?

If so how (points only awarded if possible)

I want to pul of account names, usernames and groups in (only)


Who is Participating?
rherguthConnect With a Mentor Commented:
You can pull logins and groups through Active Directory using a linked server in SQL Server 2000.  Unfortunately, you cannot pull the users names that are in a particular group because the datatype returned by ADSI is not supported by SQL Server.

-- Link the server
EXEC sp_addlinkedserver 'ADSI', 'Active Directory Services 2.5', 'ADSDSOObject', 'adsdatasource'
-- Set the password
EXEC sp_addlinkedsrvlogin 'ADSI', false, 'sa', 'CN=Administrator,OU=Users - Admins,DC=myserver,DC=mydomain,DC=com', 'pwd'

Sample query grabs groups from domain
FROM OpenQuery(ADSI, '

sample Query grabs data from exchange server:
      DomainUsers.displayName [DisplayName]
      , DomainUsers.title [Title]
      , DomainUsers.mail [EMail]
      , DomainUsers.TelephoneNumber [Phone]
      , DomainUsers.facsimileTelephoneNumber [FAX]
      , DomainUsers.sAMAccountName [DomainAccount]
      , DomainUsers.mailnickname [ExchangeAccount]
      , DomainUsers.homephone [WebURL]
      , DomainUsers.pager [Pager]
      , [MobilePhone]
      , DomainUsers.postalcode [ZIPCode]
--      , DomainUsers.primarygroupid
--      , DomainUsers.adsPath
--      , DomainUsers.distinguishedName [DN]
--      , [CN]
--      , [LastName]
--      , DomainUsers.givenName [FirstName]
--      , DomainUsers.[name] [ADS Name]
--      , DomainUsers.thumbnailPhoto
      OpenQuery (ADSI,
            sn, givenName, name, displayName, cn, title, TelephoneNumber, facsimileTelephoneNumber
            , mailnickname, distinguishedName, homephone, pager, mobile, postalcode
            , sAMAccountName, mail, adsPath, primarygroupid, thumbnailPhoto;
      ) [DomainUsers]
      -- DisplayName must have a comma
      And IsNull(CHARINDEX(',', DomainUsers.displayName), 0) > 0

-- drop the linked server (Optional but recommended, you could just leave it available)
EXEC sp_droplinkedsrvlogin 'ADSI', 'sa'
EXEC sp_dropserver 'ADSI'
CorvalionAuthor Commented:
not quite what i was looking for was, I want to import user accounts from the domain with usergroups
Improve Your Query Performance Tuning

In this FREE six-day email course, you'll learn from Janis Griffin, Database Performance Evangelist. She'll teach 12 steps that you can use to optimize your queries as much as possible and see measurable results in your work. Get started today!

Guy Hengel [angelIII / a3]Billing EngineerCommented:
Did the above links already give you ideas, have you problems using them or what?
Are you using SQL Server or not, if not specify?
WE ARE NOT SITTING IN FRONT OF YOUR DESK, you have to tell use something...
CorvalionAuthor Commented:
yer sorry SQL 2000 and the domain is on another server
i'm not sure what do you want ...
do u want each user in operating system should be assosicated one user in database ? the best way seem to be create user identified by external - u do need to enter password while logging in, but u can connect into oracle only when you are connected into operating system under the same user under which db user was created - u r identified by external user (operating system user)

if u ant to store the same user/role structure in oracle as u have in operating system look for some "identity manager" software and adapter for oracle for it
CorvalionAuthor Commented:
I am trying to get the user account details from an NT domain server so i can inport the accounts when they are created for normal NT use and exchange use. other than that I cant explain any better which made it had to look for.
I like my answer :)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.