Solved

Can SQL pull user accounts from a domain server ?

Posted on 2004-10-07
11
283 Views
Last Modified: 2008-02-01
If so how (points only awarded if possible)

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

thanks

Corv
0
Comment
Question by:Corvalion
  • 3
  • 2
  • 2
  • +1
11 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 12247211
0
 

Author Comment

by:Corvalion
ID: 12247270
not quite what i was looking for was, I want to import user accounts from the domain with usergroups
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 12247314
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...
0
 

Author Comment

by:Corvalion
ID: 12247524
yer sorry SQL 2000 and the domain is on another server
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 9

Expert Comment

by:konektor
ID: 12247626
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
0
 

Author Comment

by:Corvalion
ID: 12247985
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.
0
 
LVL 9

Accepted Solution

by:
rherguth earned 125 total points
ID: 12253216
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'
GO
-- Set the password
EXEC sp_addlinkedsrvlogin 'ADSI', false, 'sa', 'CN=Administrator,OU=Users - Admins,DC=myserver,DC=mydomain,DC=com', 'pwd'
GO

Sample query grabs groups from domain
SELECT name
FROM OpenQuery(ADSI, '
      <GC://OU=Users,DC=myserver,DC=mydomain,DC=com>;(&(objectCategory=group)(name=*));name,adsPath'
)

sample Query grabs data from exchange server:
SELECT
      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
FROM
      OpenQuery (ADSI,
            '<LDAP://DC=myserver,DC=mydomain,DC=com>;(&(objectCategory=person)(objectClass=user));
            sn, givenName, name, displayName, cn, title, TelephoneNumber, facsimileTelephoneNumber
            , mailnickname, distinguishedName, homephone, pager, mobile, postalcode
            , sAMAccountName, mail, adsPath, primarygroupid, thumbnailPhoto;
            subtree'
      ) [DomainUsers]
WHERE DomainUsers.sn IS NOT NULL
      -- DisplayName must have a comma
      And IsNull(CHARINDEX(',', DomainUsers.displayName), 0) > 0
ORDER BY
      DomainUsers.sn
      ,DomainUsers.givenName

-- drop the linked server (Optional but recommended, you could just leave it available)
EXEC sp_droplinkedsrvlogin 'ADSI', 'sa'
EXEC sp_dropserver 'ADSI'
GO
0
 
LVL 9

Expert Comment

by:rherguth
ID: 12718297
I like my answer :)
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction: Often, when running a query with joins, the results show up "duplicates", and often, those duplicates can be "eliminated" in the results using DISTINCT, for example. Using DISTINCT is simple: just add it after the SELECT keyword, an…
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now