Yes ADSI as linked server is not well documented. It works well for basic queries: no updates. You need a service AD account and add this as any linked server in SQLSERVER: you can sp_addlinkedserver ... I do not remember the syntax OR use EM to add linked
server. After which query from this like from linked server. Something similar:
-- Add the linked server via SQL
sp_addlinkedserver 'ADSI', 'Active Directory Service Interfaces', 'ADSDSOObject', 'adsdatasource'
EXEC sp_addlinkedsrvlogin 'ADSI', 'false'
raghu1
Contributor
2004 Points
558 Posts
Re: Connection Strings
Jun 13, 2008 02:36 PM|LINK
Yes ADSI as linked server is not well documented. It works well for basic queries: no updates. You need a service AD account and add this as any linked server in SQLSERVER: you can sp_addlinkedserver ... I do not remember the syntax OR use EM to add linked server. After which query from this like from linked server. Something similar:
-- Add the linked server via SQL
sp_addlinkedserver 'ADSI', 'Active Directory Service Interfaces', 'ADSDSOObject', 'adsdatasource'
EXEC sp_addlinkedsrvlogin 'ADSI', 'false'
--Query
SELECT * FROM OpenQuery(
ADSI,
'select
cn,
sn,
instanceType,
primaryGroupID,
whenCreated,
whenChanged,
sAMAccountName,
sAMAccountType,
objectCategory,
givenName,
distinguishedName,
displayName,
name,
telephoneNumber,
mail,
userPrincipalName,
userAccountControl
FROM ''LDAP://YourAdDomain/DC=...'' where objectClass = ''User''')
I could get the above working. Remember this brings up only first 1000 records. To test if a single account is valid, this works