Note - there is a big limitation with using this - only the first 1000 entries will be selected
You need to initially create the Active Directory database as a linked server.
The script uses subquerys to allow for manipulation in the SELECT Field1,Field2,Field3,Field4 FROM statement and you will have to put in your own AD specific details for the parameters and fields.
Apologies for the code formating problems I had with this - remove the underscores
-- to link AD Server
-- sp_addlinkedserver 'ADSI', 'Active Directory Service Interfaces', 'ADSDSOObject', 'adsdatasource'
BEGIN TRANSACTION
TRUNCATE TABLE AdUserDetails
INSERT INTO AdUserDetails (Field1, Field2, Field3, Field4)
-- Select the required fields from Active Directory
SELECT Field1,Field2,Field3,Field4 FROM
(SELECT TOP 100 PERCENT *
FROM OPENQUERY(ADSI,
'<LDAP:/ /dc=YourADParam1,dc=YourADParam2,dc=YourADParam3>;(&(objectCategory=person)(objectClass=user)(name=*));AdField1,AdField2,AdField3,AdField4;subtree') AS t
WHERE AdField3 IS NOT NULL) AS ad
COMMIT TRANSACTION
select * from AdUserDetails
No comments:
Post a Comment