Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save R41D3NN/19ba4b2bc438a872d12de5832f38ff61 to your computer and use it in GitHub Desktop.

Select an option

Save R41D3NN/19ba4b2bc438a872d12de5832f38ff61 to your computer and use it in GitHub Desktop.
Secret Server report to show discovered AD Users and each group they are in. Each group is in it's own row.
SELECT
A.[OU DN],
A.[AccountName],
Split.a.value('.', 'VARCHAR(1000)') AS [Group]
FROM (
SELECT
[ou].[DistinguishedName] AS 'OU DN',
[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)
ORDER BY
[Group],
A.[OU DN],
A.[AccountName]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment