Saturday, February 25, 2012

Retrieve GUID or SID FROM Active Directory via ADSI and T-SQL only?

Hi all,

is there a way to get an object's SID or GUID using T-SQL only?

Up to now I got the following code of Active Directory Service Interfaces working,

but GUID or SID are not among the parameters known to me.

Code Snippet

EXEC sp_addlinkedserver 'ADSI', 'Active Directory Service Interfaces', 'ADSDSOObject', 'adsdatasource'

SELECT * FROM OpenQuery(ADSI, 'SELECT title, displayName, sAMAccountName, givenName, telephoneNumber, facsimileTelephoneNumber, sn FROM ''LDAP://DC=whatever,DC=domain,DC=org'' where objectClass = ''User''')

I do not want to use anything other then SQL Server 2000 to get an AD-object's primary key.

Any comments would be appreciated.

Thank you!

Regards,

caracol

Windows 2000 Server, SQL Server 2000, AD in W2K only mode

This is not an SSIS question. Moving to the Transact-SQL Forum.|||

Hi all,

just in case there should be someone else looking for identifiable data to be extracted from Active Directory:

A complete list with all attributes can be found at

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/adschema/adschema/attributes_all.asp

For every attribute the LDAP-Display-Name is given which can be accessed by ADSI.

My SELECT from above should be

Code Snippet

SELECT * FROM OpenQuery(ADSI, 'SELECT objectGUID, title, displayName, sAMAccountName, givenName, telephoneNumber, facsimileTelephoneNumber, sn FROM ''LDAP://DC=whatever,DC=domain,DC=org'' where objectClass = ''User''')

then.

Regards,

caracol

No comments:

Post a Comment