Active Directory data into SQL table

前端 未结 4 1091
有刺的猬
有刺的猬 2020-12-06 02:13

How would I extract Active Directory info (Username, first name, surname) and populate an SQL table with the results?

Many thanks

Scott

4条回答
  •  情歌与酒
    2020-12-06 03:05

    If you just need it in SQL, I'm using the code below

    INSERT...
    SELECT A.SAMAccountName, A.Mail,  A.displayName  FROM
        (SELECT * FROM OpenQuery(ADSI, 'SELECT title, displayName, sAMAccountName, givenName, telephoneNumber, facsimileTelephoneNumber, sn, userAccountControl,mail  
        FROM ''LDAP://domain.ro/DC=domain,DC=ro'' where objectClass = ''User''')
        WHERE (sn is not null) and (givenName is not null) and (mail is not null) )A
    

    where ADSI is a linked server created based on this: http://msdn2.microsoft.com/en-us/library/aa772380(VS.85).aspx

提交回复
热议问题