Skip to content

Commit ee3658c

Browse files
authored
Merge pull request #4799 from PitSysAdmin/TransitiveGroupMembers
Adding Transitive parameter to Get-PnPAzureADGroupMember
2 parents dc8904d + 004d184 commit ee3658c

File tree

4 files changed

+42
-8
lines changed

4 files changed

+42
-8
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
6161
- Added `Get-PnPMicrosoft365Roadmap` which allows retrieval of the Microsoft 365 Roadmap items [#4764](https://github.com/pnp/powershell/pull/4764)
6262
- Added `-Name` parameter to `Add-PnPApplicationCustomizer` cmdlet to allow for specifying the name of the application customizer [#4767](https://github.com/pnp/powershell/pull/4767)
6363
- Added `Get-PnPTraceLog` cmdlet which allows reading from the detailed in memory logs of the PnP PowerShell cmdlet execution [#4794](https://github.com/pnp/powershell/pull/4794)
64+
- Added `-Transitive` parameter to `Get-PnPAzureADGroupMember` cmdlet to allow members of groups inside groups to be retrieved [#4799](https://github.com/pnp/powershell/pull/4799)
6465

6566
### Changed
6667

@@ -143,6 +144,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
143144

144145
### Contributors
145146

147+
- [PitSysAdmin]
146148
- Abhijeet Jadhav [TekExpo]
147149
- [abwlodar]
148150
- [jgfgoncalves]

documentation/Get-PnPAzureADGroupMember.md

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ title: Get-PnPAzureADGroupMember
1515

1616
* Microsoft Graph API : One of Directory.Read.All, Directory.ReadWrite.All, Group.Read.All, Group.ReadWrite.All, GroupMember.Read.All, GroupMember.ReadWrite.All, User.Read.All, User.ReadWrite.All
1717

18-
Gets members of a particular Azure Active Directory group. This can be a security, distribution or Microsoft 365 group.
18+
Gets members of a particular Entra ID group. This can be a security, distribution or Microsoft 365 group.
1919

2020
## SYNTAX
2121

2222
```powershell
23-
Get-PnPAzureADGroupMember -Identity <AzureADGroupPipeBind> [-Connection <PnPConnection>]
23+
Get-PnPAzureADGroupMember -Identity <AzureADGroupPipeBind> [-Connection <PnPConnection>] [-Transitive]
2424
```
2525

2626
## DESCRIPTION
2727

28-
Allows to list members from given Azure Active Directory group. This can be a security, distribution or Microsoft 365 group.
28+
Allows to list members from given Entra ID group. This can be a security, distribution or Microsoft 365 group.
2929

3030
## EXAMPLES
3131

@@ -34,19 +34,26 @@ Allows to list members from given Azure Active Directory group. This can be a se
3434
Get-PnPAzureADGroupMember -Identity $groupId
3535
```
3636

37-
Retrieves all the members of a specific Azure Active Directory group based on its ID.
37+
Retrieves all the direct members of a specific Entra ID group based on its ID.
3838

3939
### EXAMPLE 2
4040
```powershell
4141
Get-PnPAzureADGroupMember -Identity $group
4242
```
4343

44-
Retrieves all the members of a specific Azure Active Directory group based on the group's object instance.
44+
Retrieves all the direct members of a specific Entra ID group based on the group's object instance.
45+
46+
### EXAMPLE 3
47+
```powershell
48+
Get-PnPAzureADGroupMember -Identity $group -Transitive
49+
```
50+
51+
Retrieves all the direct and transitive members (members of groups inside groups) of a specific Entra ID group based on the group's object instance.
4552

4653
## PARAMETERS
4754

4855
### -Identity
49-
The Identity of the Azure Active Directory group.
56+
The Identity of the Entra ID group.
5057

5158
```yaml
5259
Type: AzureADGroupPipeBind
@@ -73,6 +80,20 @@ Accept pipeline input: False
7380
Accept wildcard characters: False
7481
```
7582
83+
### -Transitive
84+
If provided, the direct and transitive members (members of groups in the group) of a group will be returned. If not provided, only the members directly assigned to the group will be returned.
85+
86+
```yaml
87+
Type: SwitchParameter
88+
Parameter Sets: (All)
89+
90+
Required: False
91+
Position: Named
92+
Default value: False
93+
Accept pipeline input: False
94+
Accept wildcard characters: False
95+
```
96+
7697
## RELATED LINKS
7798
7899
[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)

src/Commands/AzureAD/GetAzureADGroupMember.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ public class GetAzureADGroupMember : PnPGraphCmdlet
1818
[Parameter(Mandatory = true, ValueFromPipeline = true)]
1919
public AzureADGroupPipeBind Identity;
2020

21+
[Parameter(Mandatory = false, ValueFromPipeline = false)]
22+
public SwitchParameter Transitive;
23+
2124
protected override void ExecuteCmdlet()
2225
{
2326
Group group = null;
@@ -30,8 +33,11 @@ protected override void ExecuteCmdlet()
3033
if (group != null)
3134
{
3235
// Get members of the group
33-
var members = Microsoft365GroupsUtility.GetMembers(GraphRequestHelper, new Guid(group.Id));
34-
WriteObject(members?.OrderBy(m => m.DisplayName), true);
36+
var members = Transitive
37+
? Microsoft365GroupsUtility.GetTransitiveMembers(GraphRequestHelper, new Guid(group.Id))
38+
: Microsoft365GroupsUtility.GetMembers(GraphRequestHelper, new Guid(group.Id));
39+
WriteObject(members?.OrderBy(m => m.DisplayName), true);
40+
3541
}
3642
}
3743
}

src/Commands/Utilities/Microsoft365GroupsUtility.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,11 @@ internal static IEnumerable<Microsoft365User> GetMembers(ApiRequestHelper reques
389389
{
390390
return GetGroupMembers(requestHelper, "members", groupId);
391391
}
392+
393+
internal static IEnumerable<Microsoft365User> GetTransitiveMembers(ApiRequestHelper requestHelper, Guid groupId)
394+
{
395+
return GetGroupMembers(requestHelper, "transitiveMembers", groupId);
396+
}
392397

393398
private static IEnumerable<Microsoft365User> GetGroupMembers(ApiRequestHelper requestHelper, string userType, Guid groupId)
394399
{

0 commit comments

Comments
 (0)