好的,所以我已经有了到服务器上Active Directory的现有连接。我知道查询Active Directory有效。我希望能够查询Active Directory中的所有组织单位和/或组,并且能够找到属于这些组/组织单位的用户。
这是当前仅提取用户信息的查询(或设置为提取所有用户的存储过程的一部分):
SELECT
userAccountControl,
DisplayName AS [NAME],
givenName AS FIRSTNAME,
middleName,
sn AS LASTNAME,
employeeID AS EMPID,
telephoneNumber AS EXT,
Title,
Department AS DEPT,
Division,
sAMAccountName AS UserName,
mail AS Email,
homeDirectory AS HomeDir,
userPrincipalName AS LOGON,
manager
FROM OPENQUERY(ADSI,
'
select
userAccountControl,
DisplayName,
givenName,
middleName,
sn,
employeeID,
telephoneNumber,
Title,
Department,
Division,
sAMAccountName,
mail,
homeDirectory,
userPrincipalName,
manager
from ''LDAP://name''
where sn > ''a''
and sn <''h''
order by DisplayName
')
AS derivedtbl_1