Go Premium for a chance to win a PS4. Enter to Win

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 336
  • Last Modified:

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)


  • 3
  • 2
  • 2
  • +1
1 Solution
CorvalionAuthor Commented:
not quite what i was looking for was, I want to import user accounts from the domain with usergroups
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...
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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.
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]
      , DomainUsers.mobile [MobilePhone]
      , DomainUsers.postalcode [ZIPCode]
--      , DomainUsers.primarygroupid
--      , DomainUsers.adsPath
--      , DomainUsers.distinguishedName [DN]
--      , DomainUsers.cn [CN]
--      , DomainUsers.sn [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]
WHERE DomainUsers.sn IS NOT NULL
      -- 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'
I like my answer :)

Featured Post

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

  • 3
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now