User Rating: 0 / 5

Star InactiveStar InactiveStar InactiveStar InactiveStar Inactive
 

/******************************************************************************

Script      :  GetADGroupMembers
Author      :  Jeff 
Description :  Returns a list of Active Directory groups and the members
               included in the group.
Notes       :  If using this you may get an error with groups that do not
               exist within AD, or access is not aloud.  You can filter that 
               group out in the WHERE clause of the c_Group cursor.

******************************************************************************/
BEGIN
   SET NOCOUNT ON
   SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
   SET DEADLOCK_PRIORITY LOW
   --
   DECLARE @GroupName    VARCHAR(60)
   --
   CREATE TABLE #tempGroupMembers (AccountName     VARCHAR(60),
                                   Type            VARCHAR(10),
                                   Privilege       VARCHAR(10),
                                   MappedLoginName VARCHAR(60),
                                   PermissionPath  VARCHAR(60))
   --
   DECLARE c_Group CURSOR FOR
      SELECT sl.name
      FROM master..syslogins  sl
      WHERE sl.isntgroup = 1
        AND sl.name NOT LIKE '%NT Authority%'
        AND sl.name NOT LIKE '%NT SERVICE%'
        AND sl.name NOT LIKE '%$%'
      ORDER BY sl.name
   --
   OPEN c_Group
   FETCH NEXT FROM c_Group INTO @GroupName
   WHILE @@FETCH_STATUS = 0
       BEGIN
          INSERT #tempGroupMembers
          EXEC master.. xp_logininfo @GroupName, 'members'
          FETCH NEXT FROM c_Group INTO @GroupName
       END
   --
   CLOSE c_Group
   DEALLOCATE c_Group
   --
   SELECT CAST(@@SERVERNAME AS VARCHAR(60))  AS [Instance],
          tgm.PermissionPath                 AS [GroupName],
          tgm.AccountName                    AS [Login]
   FROM #tempGroupMembers tgm
   --      
   DROP TABLE #tempGroupMembers
   --   
END -- Code Block

 

Add comment


Security code
Refresh

0
0
0
s2sdefault