[SQL]SQL and Active Directory - How to use SQL to Query AD

2013-09-19

Situation:

Why just don't use AD management Tool or PowerShell to query rather than using MSSQL!!!

This's definitely a tough problem to figure it out. but I am an IT guy, when you are experiencing issues and need to engage it without serious irritative reaction

Solution:

Using LinkServer
 
1. Add Active Directory Link Server into MSSQL

(concise)
or

2. Add Link Server Account/Password (option)

 

3. Prepare your OpenQuery , default MSSQL not allow use OpenQuery
  • check status
 
  • using " Ad Hoc Distributed Queries" to open OpenQuery
 

4. Query your Active Directory

 

 *you can use "objectCategory" to shrink the Scope Range instead of using "objectClass"


Without Using LinkServer
Newer Older