SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 SQL Server Administration (2012)
 Method that works to Query Active Directory
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Analyzer
Posting Yak Master

United Kingdom
101 Posts

Posted - 03/19/2014 :  06:19:15  Show Profile  Reply with Quote
Wish to cross check all logins (sql/NT) across sql estate against current logins list inside Active Directory with "Enabled" with the view to purge orphan logins.

I'm using the below syntax the LinkedServer + query but getting the error below. Any ideas where my syntax is incorrect?


EXEC sp_addlinkedserver 'ADSI', 'Active Directory Services 2.5', 'ADSDSOObject', 'myDCServer'

SELECT sAMAccountName
FROM OPENQUERY(ADSI, 'SELECT sAMAccountName, userAccountControl
FROM ''LDAP://DC=myDCServer,DC=com,DC=uk''
WHERE objectCategory = ''Person''
AND objectClass = ''user''')
WHERE userAccountControl & 2 <> 0; -- disabled

Error:

Msg 7321, Level 16, State 2, Line 2
An error occurred while preparing the query "SELECT sAMAccountName, userAccountControl
FROM 'LDAP://DC=GBLTCPRDADC01,DC=com,DC=uk'
WHERE objectCategory = 'Person'
AND objectClass = 'user'" for execution against OLE DB provider "ADSDSOObject" for linked server "ADSI".
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.09 seconds. Powered By: Snitz Forums 2000