Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion documentation/Remove-PnPAzureADGroupMember.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ Removes members from a particular Azure Active Directory group. This can be a se
## SYNTAX

```powershell
Remove-PnPAzureADGroupMember -Identity <AzureADGroupPipeBind> -Users <String[]>
Remove-PnPAzureADGroupMember -Identity <AzureADGroupPipeBind> -Users <String[]>
Copy link

Copilot AI Nov 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The syntax section should include parameter set names to clarify which parameters belong to which set. Consider adding '### ByUPN' and '### ByObjectId' headings above each syntax example, similar to standard PowerShell documentation format.

Copilot uses AI. Check for mistakes.
```

```powershell
Remove-PnPAzureADGroupMember -Identity <AzureADGroupPipeBind> -MemberObjectId <Guid[]>
```

## DESCRIPTION
Expand All @@ -36,6 +40,22 @@ Remove-PnPAzureADGroupMember -Identity "Project Team" -Users "john@contoso.onmic

Removes the provided two users as members from the Azure Active Directory group named "Project Team"

### EXAMPLE 2
```powershell
# Remove a nested group by its ObjectId
Remove-PnPAzureADGroupMember -Identity $parentGroupId -MemberObjectId $childGroupId
```

Removes the group with ObjectId `$childGroupId` from the group identified by `$parentGroupId`.

### EXAMPLE 3
```powershell
# Pipeline by property name (Id)
Get-PnPAzureADGroupMember -Identity $parentGroupId | Where-Object { $_.Id -eq $childGroupId } | Remove-PnPAzureADGroupMember -Identity $parentGroupId
```

Pipes a member (group or user) whose `Id` matches `$childGroupId` into the cmdlet and removes it.

## PARAMETERS

### -Identity
Expand Down Expand Up @@ -66,6 +86,20 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -MemberObjectId
The ObjectId(s) of directory object(s) (Users or Groups) to remove from the Azure Active Directory group. Use this to remove nested groups that do not have a UPN.

```yaml
Type: Guid[]
Parameter Sets: ByObjectId

Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```

## RELATED LINKS

[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)
Expand Down
34 changes: 34 additions & 0 deletions documentation/Remove-PnPAzureADGroupOwner.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ Removes owners from a particular Azure Active Directory group. This can be a sec
Remove-PnPAzureADGroupOwner -Identity <AzureADGroupPipeBind> -Users <String[]> [-Verbose]
Copy link

Copilot AI Nov 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The syntax section should include parameter set names to clarify which parameters belong to which set. Consider adding '### ByUPN' and '### ByObjectId' headings above each syntax example, similar to standard PowerShell documentation format.

Copilot uses AI. Check for mistakes.
```

```powershell
Remove-PnPAzureADGroupOwner -Identity <AzureADGroupPipeBind> -MemberObjectId <Guid[]> [-Verbose]
```

## DESCRIPTION

Allows to remove owners from Azure Active Directory group.
Expand All @@ -36,6 +40,22 @@ Remove-PnPAzureADGroupOwner -Identity "Project Team" -Users "john@contoso.onmicr

Removes the provided two users as owners from the Azure Active Directory group named "Project Team".

### EXAMPLE 2
```powershell
# Remove an owner by ObjectId
Remove-PnPAzureADGroupOwner -Identity $groupId -MemberObjectId $ownerObjectId
```

Removes the owner (user or group) with ObjectId `$ownerObjectId` from the group identified by `$groupId`.

### EXAMPLE 3
```powershell
# Pipeline by property name (Id)
Get-PnPAzureADGroupOwner -Identity $groupId | Where-Object { $_.Id -eq $ownerObjectId } | Remove-PnPAzureADGroupOwner -Identity $groupId
```

Pipes an owner whose `Id` matches `$ownerObjectId` into the cmdlet and removes it.

## PARAMETERS

### -Identity
Expand Down Expand Up @@ -66,6 +86,20 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -MemberObjectId
The ObjectId(s) of directory object(s) (Users or Groups) to remove from the Azure Active Directory group as owners. Use this to remove owners that do not have a UPN.

```yaml
Type: Guid[]
Parameter Sets: ByObjectId

Required: True
Position: Named
Default value: None
Accept pipeline input: True (ByPropertyName)
Accept wildcard characters: False
```

## RELATED LINKS

[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)
Expand Down
20 changes: 16 additions & 4 deletions src/Commands/AzureAD/RemoveAzureADGroupMember.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,22 @@

namespace PnP.PowerShell.Commands.Graph
{
[Cmdlet(VerbsCommon.Remove, "PnPAzureADGroupMember")]
[Cmdlet(VerbsCommon.Remove, "PnPAzureADGroupMember", DefaultParameterSetName = "ByUPN")]
[RequiredApiDelegatedOrApplicationPermissions("graph/Group.ReadWrite.All")]
[Alias("Remove-PnPEntraIDGroupMember")]
public class RemoveAzureADGroupMember : PnPGraphCmdlet
{
[Parameter(Mandatory = true, ValueFromPipeline = true)]
[Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = "ByUPN")]
[Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = "ByObjectId")]
public AzureADGroupPipeBind Identity;

[Parameter(Mandatory = true)]
[Parameter(Mandatory = true, ParameterSetName = "ByUPN")]
public string[] Users;

[Parameter(Mandatory = true, ParameterSetName = "ByObjectId", ValueFromPipelineByPropertyName = true)]
[Alias("ObjectId", "Id")]
public System.Guid[] MemberObjectId;

protected override void ExecuteCmdlet()
{
Group group = null;
Expand All @@ -29,7 +34,14 @@ protected override void ExecuteCmdlet()

if (group != null)
{
Microsoft365GroupsUtility.RemoveMembers(GraphRequestHelper, new System.Guid(group.Id), Users);
if (ParameterSetName == "ByUPN" && Users != null && Users.Length > 0)
{
Microsoft365GroupsUtility.RemoveMembers(GraphRequestHelper, new System.Guid(group.Id), Users);
}
else if (ParameterSetName == "ByObjectId" && MemberObjectId != null && MemberObjectId.Length > 0)
{
Microsoft365GroupsUtility.RemoveDirectoryMembers(GraphRequestHelper, new System.Guid(group.Id), MemberObjectId);
}
}
}
}
Expand Down
20 changes: 16 additions & 4 deletions src/Commands/AzureAD/RemoveAzureADGroupOwner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,22 @@

namespace PnP.PowerShell.Commands.Graph
{
[Cmdlet(VerbsCommon.Remove, "PnPAzureADGroupOwner")]
[Cmdlet(VerbsCommon.Remove, "PnPAzureADGroupOwner", DefaultParameterSetName = "ByUPN")]
[RequiredApiDelegatedOrApplicationPermissions("graph/Group.ReadWrite.All")]
[Alias("Remove-PnPEntraIDGroupOwner")]
public class RemoveAzureADGroupOwner : PnPGraphCmdlet
{
[Parameter(Mandatory = true, ValueFromPipeline = true)]
[Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = "ByUPN")]
[Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = "ByObjectId")]
public AzureADGroupPipeBind Identity;

[Parameter(Mandatory = true)]
[Parameter(Mandatory = true, ParameterSetName = "ByUPN")]
public string[] Users;

[Parameter(Mandatory = true, ParameterSetName = "ByObjectId", ValueFromPipelineByPropertyName = true)]
[Alias("ObjectId", "Id")]
public System.Guid[] MemberObjectId;

protected override void ExecuteCmdlet()
{
Group group = null;
Expand All @@ -29,7 +34,14 @@ protected override void ExecuteCmdlet()

if (group != null)
{
Microsoft365GroupsUtility.RemoveOwners(GraphRequestHelper, new System.Guid(group.Id), Users);
if (ParameterSetName == "ByUPN" && Users != null && Users.Length > 0)
{
Microsoft365GroupsUtility.RemoveOwners(GraphRequestHelper, new System.Guid(group.Id), Users);
}
else if (ParameterSetName == "ByObjectId" && MemberObjectId != null && MemberObjectId.Length > 0)
{
Microsoft365GroupsUtility.RemoveDirectoryOwners(GraphRequestHelper, new System.Guid(group.Id), MemberObjectId);
}
}
}
}
Expand Down
16 changes: 16 additions & 0 deletions src/Commands/Utilities/Microsoft365GroupsUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,22 @@ internal static void RemoveMembers(ApiRequestHelper requestHelper, Guid groupId,
RemoveUserFromGroup(requestHelper, "members", groupId, users);
}

internal static void RemoveDirectoryMembers(ApiRequestHelper requestHelper, Guid groupId, Guid[] directoryObjects)
{
foreach (var dirObject in directoryObjects)
{
requestHelper.Delete($"v1.0/groups/{groupId}/members/{dirObject}/$ref");
}
}

internal static void RemoveDirectoryOwners(ApiRequestHelper requestHelper, Guid groupId, Guid[] directoryObjects)
{
foreach (var dirObject in directoryObjects)
{
requestHelper.Delete($"v1.0/groups/{groupId}/owners/{dirObject}/$ref");
}
}

private static void RemoveUserFromGroup(ApiRequestHelper requestHelper, string groupName, Guid groupId, string[] users)
{
foreach (var user in users)
Expand Down
Loading