Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save R41D3NN/2f83d5ded6ae8eb597fef580d94416ee to your computer and use it in GitHub Desktop.
Save R41D3NN/2f83d5ded6ae8eb597fef580d94416ee to your computer and use it in GitHub Desktop.
Secret Server report to show discovered total AD users per group.
SELECT
B.[Group],
COUNT(B.[AccountName]) AS [Total Members]
FROM (
SELECT
Split.a.value('.', 'VARCHAR(1000)') AS [Group],
A.[AccountName]
FROM (
SELECT
[ca].[AccountName],
CAST ('<M>' + REPLACE(REPLACE(REPLACE(REPLACE([ca].[SearchGroups], '&', '\u0026'), '<', '\u003C'), '>', '\u003E'), CHAR(59), '</M><M>') + '</M>' AS XML) AS [Group]
FROM [tbComputerAccount] [ca]
JOIN [tbOrganizationUnit] [ou] ON [ca].[OrganizationUnitId] = [ou].[OrganizationUnitId]
) AS A
CROSS APPLY [Group].nodes ('/M') AS Split(a)
) B
GROUP BY
[Group]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment