Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

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

Posting Yak Master

United Kingdom
115 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


Msg 7321, Level 16, State 2, Line 2
An error occurred while preparing the query "SELECT sAMAccountName, userAccountControl
WHERE objectCategory = 'Person'
AND objectClass = 'user'" for execution against OLE DB provider "ADSDSOObject" for linked server "ADSI".
  Previous Topic Topic Next 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.02 seconds. Powered By: Snitz Forums 2000