Execution Flow
Synopsis
Enhanced recursive member resolution with a configurable -Depth limit (0–10). At depth 0, Get-ADGroupMember -Recursive is used directly (full recursion via AD module). At deeper levels, direct members are fetched and nested groups are expanded manually. For user accounts, Get-ADUser -Properties DisplayName is called to show the person's real name. A visited-hashtable prevents infinite loops in circular group memberships.
See also: Get-sqmADGroupMembers (simple, no depth control) and Get-sqmADMemberGroups (inverse: which groups contain a user).
Syntax
Get-sqmADGroupMembersRecursive -GroupName <String[]> # required, pipeline [-Domain <String>] [-Depth <Int>] # 0-10, default 2 [-OutputPath <String>]
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
| -GroupName | String[] | Required | AD group name(s). Accepts pipeline input. |
| -Domain | String | auto-detect | AD domain. Auto-detected from current domain if omitted. |
| -Depth | Int | 2 | Maximum nesting depth for group expansion (0–10). 0 = flat list only. |
| -OutputPath | String | C:\System\WinSrvLog\MSSQL | Directory for TXT and CSV report files. |
Return Value
| Property | Description |
|---|---|
| GroupName | Resolved group name. |
| Depth | Maximum depth used for expansion. |
| MemberCount | Unique member count after deduplication. |
| Members | List with SamAccountName, DisplayName, ObjectClass, Depth. |
| TxtFile / CsvFile | Written report file paths. |
| Status | OK / Warning / Error. |
Examples
# Resolve up to 3 nesting levels Get-sqmADGroupMembersRecursive -GroupName "DL_SQL_Admins" -Depth 3 # Flat list only (no nested group expansion) Get-sqmADGroupMembersRecursive -GroupName "DL_SQL_Admins" -Depth 0 # Multiple groups via pipeline "DL_SQL_Admins","DL_SQL_Readers" | Get-sqmADGroupMembersRecursive -Depth 2