首先,我需要在SQL Server中检索属于特定组成员的用户列表.我确实设法在网上找到了一些东西,它完美地工作.解决方案如下所示:
CREATE PROCEDURE [dbo].[NES_GetADGroupMembers] (@groupName VARCHAR(max)) AS BEGIN CREATE TABLE #MemberOfGroups ( groupName varchar(400), cn varchar(400), displayName varchar(400) ) SET NOCOUNT ON DECLARE @t varchar(100), @t2 varchar(1000), @ot varchar (4000), @tt varchar (4000); DECLARE gC CURSOR FOR SELECT cn, distinguishedName FROM openquery (ADSI, 'SELECT cn, distinguishedName FROM ''''LDAP://Mydomaindomain/CN=users,DC=Mydomain,DC=com'''' WHERE objectCategory = ''group''') OPEN gC FETCH NEXT FROM gC INTO @t, @t2 WHILE @@FETCH_STATUS = 0 BEGIN SET @ot = '''SELECT cn, displayName FROM ''''LDAP://Mydomaindomain/CN=users,DC=Mydomain,DC=com'''' WHERE objectCategory = ''''Person'''' AND objectClass = ''''user'''' AND memberOf=''''' + @t2 + ''''''; SET @tt = 'select '+ ''''+@t+'''' +' As groupName, cn, displayName from openquery(ADSI,'+ @ot +''') order by cn' INSERT INTO #MemberOfGroups (groupName, cn, displayName) EXEC (@tt) FETCH NEXT FROM gC INTO @t, @t2 END CLOSE gC DEALLOCATE gC SELECT groupName, displayName FROM #MemberOfGroups
目前,它只是工作正常,返回输入组的用户.
但是,我有一个新请求,即一个组可以将其他"组"作为成员,就像用户一样.
我尝试在WHERE条件中更新我的过滤器以包含objectClass = ''group''
,但它不起作用.
任何人都知道这些查询,并可以帮助我检索组(输入组的成员)?