With 'xp_logininfo' we can pull members of AD Security Groups
/* all groups user is member and group granting access */
EXEC xp_logininfo 'Domain\WindowsUser', 'all';
/* all user is in group */
EXEC xp_logininfo 'Domain\WindowsGroup', 'members';
Problem: I have inherited many security groups and found duplicate: Groups either have the same members but different access or Same access different members in groups Some groups no longer have members at all
Idea: I want to find all the Windows Groups drop them in a table then (and this is where I need a smarted DBA) create a new table using 'xp_logininfo' to execute on every name name in the first table
select
[name]
from [sys].[database_principals]
where [type] in ('G')
Insert Into #temptable1 ([name])
(theory)
EXEC xp_logininfo '#temptable1', 'members';
CREATE TABLE #temptable2 ( [account name] nvarchar(128), [type] varchar(8), [privilege] varchar(8), [mapped login name] nvarchar(128), [permission path] nvarchar(128) )
INSERT INTO #temptable2 ([account name], [type], [privilege], [mapped login name], [permission path])
So far I am able to pull members of AD Security Groups 1 at a time but with over 800 groups just collecting the data and moving it into excel to compare has been a time consuming task.
If anyone has done this or has an idea how I can speed this up I'd love the assistance.
I'd like to add I'm dyslexic so if I need to re-explain any of this please let me know.
Update: I found this: Enumerate Windows Group Members Lowell Izaguirre, 2017-02-24 (first published: 2016-03-17)
Info - https://www.sqlservercentral.com/articles/enumerate-windows-group-members Code - https://www.sqlservercentral.com/wp-content/uploads/2019/05/EnumerateWindowsGroupMembers.sql
I used this to write the results to a table and compared the data