OK, here it is, i was trying to create a timetable SharePoint webpart for our school, and using SQL Server Database. And i want the timetable appears as the domain user logged on to SharePoint. So my first step to create this webpart was creating the database and tables. From the previous topic i have explained how to get the Active directory users and attributes, and so i improved the sql query to copy all my AD retrieval results into my 'teacher' table.
Below is the query that i ran:
use TimeTable
go
INSERT INTO teacher(initials,logOnID,preferredName)
SELECT initials,samAccountName, displayName FROM OPENQUERY(ADSI,'SELECT initials, samAccountName, displayName, mail FROM ''LDAP://OU=Teaching Faculty,OU=Staff,DC=BISDRAGONS,DC=COM'' WHERE objectClass=''Person'' AND objectClass = ''User'' ORDER BY samAccountName') where mail IS NOT NULL
go
INSERT INTO teacher(initials,logOnID,preferredName)
SELECT initials,samAccountName, displayName FROM OPENQUERY(ADSI,'SELECT initials, samAccountName, displayName, mail FROM ''LDAP://OU=Teaching Faculty,OU=Staff,DC=BISDRAGONS,DC=COM'' WHERE objectClass=''Person'' AND objectClass = ''User'' ORDER BY samAccountName') where mail IS NOT NULL
And it worked very well for me. :)
5 comments:
hi!
Can u give some more information like schema of teachers table, etc...?
Hi Sudheer, i've posted on the previous post:
Check this out: http://drekendrop.blogspot.com/2011/03/sql-query-retrieve-active-directory.html
And down there, you may find LINK for a complete Active Directory attributes in a table.
Hi, I know is a long time since this post was posted, but I wanna say thanks, you save my ass. Greetings
Hi Santiago! That sounds great, i'm happy that it helps.
exactly the part i was missing to complete my project.
cool, thanks
active directory query
Post a Comment