Sql-server – List Active Directory Users

active-directorylinked-serversql server

My boss sent to request me that: I want to a SQL query, that lists all domain users of a specific group. I began to search query. I found several solutions using Linked Server.

EXEC master.dbo.sp_addlinkedserver 
@server = N'ADSI', 
@srvproduct=N'Active Directory Service Interfaces', 
@provider=N'ADSDSOObject', 
@datasrc=N'adsdatasource'

then

EXEC master.dbo.sp_addlinkedsrvlogin 
@rmtsrvname=N'ADSI',
@useself=N'False',
@locallogin=NULL,
@rmtuser=N'DOMAIN\USER',
@rmtpassword='*********'

I replaced username and password with a domain admin user's information but I got this error

Cannot create an instance of OLE DB provider "ADsDSOObject" for linked server "ADSI".

Our domain name is akilus.local, but I didn't replace the data source.

What could the problem be?

Best Answer

I would suggest using xp_logininfo before I tried anything else more drastic. You can find more information from BOL on it.

As long as the permissions are there for the SQL Server service (being a member server in the domain) you should be able to execute the following command:

EXEC xp_logininfo 'akilus\GroupName', 'all'

If that did not work I would simply opt for doing this in PowerShell as there is much more control, and less things to configure to get it setup.