Skip to content

Commit e84ef69

Browse files
Remove parameter "-RemoveExisting" from Add-AzureAD- and M365Group-Members and -Owners (#5153)
* remove deprecated parameter from functions * update documentation * add line in changelog --------- Co-authored-by: Gautam Sheth <[email protected]>
1 parent d027994 commit e84ef69

10 files changed

+32
-108
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
5454
- Fix `Register-PnPEntraIdApp` Allow to use CER file instead of PFX [#5129](https://github.com/pnp/powershell/issues/5129)
5555

5656
### Removed
57+
- Removed `-RemoveExisting` parameter from `Add-PnPAzureADGroupMember`, `Add-PnPAzureADGroupOwner`, `Add-PnPMicrosoft365GroupMember` and `Add-PnPMicrosoft365GroupOwner` cmdlets. It was never really implemented and without function. [#5153](https://github.com/pnp/powershell/pull/5153)
5758

5859
### Contributors
5960

@@ -72,6 +73,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
7273
- Ali Robertson [alirobe]
7374
- Christian Veenhuis [ChVeen]
7475
- James Epp [jamesaepp]
76+
- Sven Boll [svenboll]
7577

7678
## [3.1.0]
7779

documentation/Add-PnPAzureADGroupMember.md

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ Adds members to a particular Azure Active Directory Group. This can be a securit
2020
## SYNTAX
2121

2222
```powershell
23-
Add-PnPAzureADGroupMember -Identity <AzureADGroupPipeBind> -Users <String[]> [-RemoveExisting] [-Connection <PnPConnection>]
23+
Add-PnPAzureADGroupMember -Identity <AzureADGroupPipeBind> -Users <String[]> [-Connection <PnPConnection>]
2424
```
2525

2626
## DESCRIPTION
2727

28-
Allows to add users to Azure Active Directory Group. This can be a security, distribution or Microsoft 365 group. By specifying `-RemoveExisting` option it is possible to first clear the group of all existing members.
28+
Allows to add users to Azure Active Directory Group. This can be a security, distribution or Microsoft 365 group.
2929

3030
## EXAMPLES
3131

@@ -38,13 +38,6 @@ Adds the provided two users as additional members to the Azure Active Directory
3838

3939
### EXAMPLE 2
4040
```powershell
41-
Add-PnPAzureADGroupMember -Identity "Project Team" -Users "[email protected]","[email protected]" -RemoveExisting
42-
```
43-
44-
Sets the provided two users as the only members of the Azure Active Directory group named "Project Team" by removing any current existing members first.
45-
46-
### EXAMPLE 3
47-
```powershell
4841
Add-PnPAzureADGroupMember -Identity "Project Team" -Users "125eaa87-7b54-41fd-b30f-2adfa68c4afe"
4942
```
5043

@@ -79,20 +72,6 @@ Accept pipeline input: True (ByValue)
7972
Accept wildcard characters: False
8073
```
8174
82-
### -RemoveExisting
83-
If provided, all existing members will be removed and only those provided through Users will become members.
84-
85-
```yaml
86-
Type: SwitchParameter
87-
Parameter Sets: (All)
88-
89-
Required: False
90-
Position: Named
91-
Default value: None
92-
Accept pipeline input: False
93-
Accept wildcard characters: False
94-
```
95-
9675
### -Users
9776
The UPN(s) of the user(s) to add to the Azure Active Directory group as a member.
9877

documentation/Add-PnPAzureADGroupOwner.md

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ Adds users to the owners of an Azure Active Directory group. This can be a secur
2020
## SYNTAX
2121

2222
```powershell
23-
Add-PnPAzureADGroupOwner -Identity <AzureADGroupPipeBind> -Users <String[]> [-RemoveExisting] [-Connection <PnPConnection>]
23+
Add-PnPAzureADGroupOwner -Identity <AzureADGroupPipeBind> -Users <String[]> [-Connection <PnPConnection>]
2424
```
2525

2626
## DESCRIPTION
2727

28-
Allows to add users to owners of an Azure Active Directory Group. This can be a security, distribution or Microsoft 365 group. By specifying `-RemoveExisting` option it is possible to first clear the group of all existing members.
28+
Allows to add users to owners of an Azure Active Directory Group. This can be a security, distribution or Microsoft 365 group.
2929

3030
## EXAMPLES
3131

@@ -38,13 +38,6 @@ Adds the provided two users as additional owners to the Azure Active Directory g
3838

3939
### EXAMPLE 2
4040
```powershell
41-
Add-PnPAzureADGroupOwner -Identity "Project Team" -Users "[email protected]","[email protected]" -RemoveExisting
42-
```
43-
44-
Sets the provided two users as the only owners of the Azure Active Directory group named "Project Team" by removing any current existing members first.
45-
46-
### EXAMPLE 3
47-
```powershell
4841
Add-PnPAzureADGroupOwner -Identity "Project Team" -Users "125eaa87-7b54-41fd-b30f-2adfa68c4afe"
4942
```
5043

@@ -79,20 +72,6 @@ Accept pipeline input: True (ByValue)
7972
Accept wildcard characters: False
8073
```
8174
82-
### -RemoveExisting
83-
If provided, all existing members will be removed and only those provided through Users will become members.
84-
85-
```yaml
86-
Type: SwitchParameter
87-
Parameter Sets: (All)
88-
89-
Required: False
90-
Position: Named
91-
Default value: None
92-
Accept pipeline input: False
93-
Accept wildcard characters: False
94-
```
95-
9675
### -Users
9776
The UPN(s) of the user(s) to add to the Azure Active Directory group as a member.
9877

documentation/Add-PnPMicrosoft365GroupMember.md

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Adds members to a particular Microsoft 365 Group.
2020
## SYNTAX
2121

2222
```powershell
23-
Add-PnPMicrosoft365GroupMember -Identity <Microsoft365GroupPipeBind> -Users <String[]> [-RemoveExisting] [-Connection <PnPConnection>]
23+
Add-PnPMicrosoft365GroupMember -Identity <Microsoft365GroupPipeBind> -Users <String[]> [-Connection <PnPConnection>]
2424
```
2525

2626
## DESCRIPTION
@@ -36,13 +36,6 @@ Add-PnPMicrosoft365GroupMember -Identity "Project Team" -Users "[email protected]
3636

3737
Adds the provided two users as additional members to the Microsoft 365 Group named "Project Team".
3838

39-
### EXAMPLE 2
40-
```powershell
41-
Add-PnPMicrosoft365GroupMember -Identity "Project Team" -Users "[email protected]","[email protected]" -RemoveExisting
42-
```
43-
44-
Sets the provided two users as the only members of the Microsoft 365 Group named "Project Team" by removing any current existing members first.
45-
4639
## PARAMETERS
4740

4841
### -Connection
@@ -73,20 +66,6 @@ Accept pipeline input: True (ByValue)
7366
Accept wildcard characters: False
7467
```
7568
76-
### -RemoveExisting
77-
If provided, all existing members will be removed and only those provided through Users will become members.
78-
79-
```yaml
80-
Type: SwitchParameter
81-
Parameter Sets: (All)
82-
83-
Required: False
84-
Position: Named
85-
Default value: None
86-
Accept pipeline input: False
87-
Accept wildcard characters: False
88-
```
89-
9069
### -Users
9170
The UPN(s) of the user(s) to add to the Microsoft 365 Group as a member.
9271

documentation/Add-PnPMicrosoft365GroupOwner.md

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Adds users to a Microsoft 365 Group as Owners.
2020
## SYNTAX
2121

2222
```powershell
23-
Add-PnPMicrosoft365GroupOwner -Identity <Microsoft365GroupPipeBind> -Users <String[]> [-RemoveExisting] [-Connection <PnPConnection>]
23+
Add-PnPMicrosoft365GroupOwner -Identity <Microsoft365GroupPipeBind> -Users <String[]> [-Connection <PnPConnection>]
2424
```
2525

2626
## DESCRIPTION
@@ -36,13 +36,6 @@ Add-PnPMicrosoft365GroupOwner -Identity "Project Team" -Users "[email protected]
3636

3737
Adds the provided two users as additional owners to the Microsoft 365 Group named "Project Team".
3838

39-
### EXAMPLE 2
40-
```powershell
41-
Add-PnPMicrosoft365GroupOwner -Identity "Project Team" -Users "[email protected]","[email protected]" -RemoveExisting
42-
```
43-
44-
Sets the provided two users as the only owners of the Microsoft 365 Group named "Project Team" by removing any current existing members first.
45-
4639
## PARAMETERS
4740

4841
### -Connection
@@ -73,20 +66,6 @@ Accept pipeline input: True (ByValue)
7366
Accept wildcard characters: False
7467
```
7568
76-
### -RemoveExisting
77-
If provided, all existing owners will be removed and only those provided through Users parameter will become owners.
78-
79-
```yaml
80-
Type: SwitchParameter
81-
Parameter Sets: (All)
82-
83-
Required: False
84-
Position: Named
85-
Default value: None
86-
Accept pipeline input: False
87-
Accept wildcard characters: False
88-
```
89-
9069
### -Users
9170
The UPN(s) of the user(s) to add to the Microsoft 365 Group as an owner.
9271

src/Commands/AzureAD/AddAzureADGroupMember.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class AddAzureADGroupMember : PnPGraphCmdlet
2020
[Parameter(Mandatory = true)]
2121
public string[] Users;
2222

23+
[Obsolete("The parameter is obsolete and will be removed in future versions. You can use Clear-PnPAzureADGroupMember instead.")]
2324
[Parameter(Mandatory = false)]
2425
public SwitchParameter RemoveExisting;
2526

@@ -39,14 +40,14 @@ protected override void ExecuteCmdlet()
3940

4041
if (userArray.Length > 0)
4142
{
42-
Microsoft365GroupsUtility.AddMembers(GraphRequestHelper, new Guid(group.Id), userArray, RemoveExisting.ToBool());
43+
Microsoft365GroupsUtility.AddMembers(GraphRequestHelper, new Guid(group.Id), userArray);
4344
}
4445

4546
var secGroups = Users.Where(x => Guid.TryParse(x, out emptyGuid)).Select(x => emptyGuid).ToArray();
4647

4748
if (secGroups.Length > 0)
4849
{
49-
Microsoft365GroupsUtility.AddDirectoryMembers(GraphRequestHelper, new Guid(group.Id), secGroups, RemoveExisting.ToBool());
50+
Microsoft365GroupsUtility.AddDirectoryMembers(GraphRequestHelper, new Guid(group.Id), secGroups);
5051
}
5152
}
5253
}

src/Commands/AzureAD/AddAzureADGroupOwner.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class AddAzureAdGroupOwner : PnPGraphCmdlet
2020
[Parameter(Mandatory = true)]
2121
public string[] Users;
2222

23+
[Obsolete("The parameter is obsolete and will be removed in future versions. You can use Clear-PnPAzureADGroupOwner instead.")]
2324
[Parameter(Mandatory = false)]
2425
public SwitchParameter RemoveExisting;
2526

@@ -41,14 +42,14 @@ protected override void ExecuteCmdlet()
4142

4243
if (userArray.Length > 0)
4344
{
44-
Microsoft365GroupsUtility.AddOwners(GraphRequestHelper, new System.Guid(group.Id), userArray, RemoveExisting.ToBool());
45+
Microsoft365GroupsUtility.AddOwners(GraphRequestHelper, new System.Guid(group.Id), userArray);
4546
}
4647

4748
var secGroups = Users.Where(x => Guid.TryParse(x, out emptyGuid)).Select(x => emptyGuid).ToArray();
4849

4950
if (secGroups.Length > 0)
5051
{
51-
Microsoft365GroupsUtility.AddDirectoryOwners(GraphRequestHelper, new System.Guid(group.Id), secGroups, RemoveExisting.ToBool());
52+
Microsoft365GroupsUtility.AddDirectoryOwners(GraphRequestHelper, new System.Guid(group.Id), secGroups);
5253
}
5354
}
5455
}

src/Commands/Microsoft365Groups/AddMicrosoft365GroupMember.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using PnP.PowerShell.Commands.Base;
33
using PnP.PowerShell.Commands.Base.PipeBinds;
44
using PnP.PowerShell.Commands.Utilities;
5+
using System;
56
using System.Management.Automation;
67

78
namespace PnP.PowerShell.Commands.Microsoft365Groups
@@ -16,12 +17,13 @@ public class AddMicrosoft365GroupMember : PnPGraphCmdlet
1617
[Parameter(Mandatory = true)]
1718
public string[] Users;
1819

20+
[Obsolete("The parameter is obsolete and will be removed in future versions. You can use Clear-PnPMicrosoft365GroupMember instead.")]
1921
[Parameter(Mandatory = false)]
2022
public SwitchParameter RemoveExisting;
2123

2224
protected override void ExecuteCmdlet()
2325
{
24-
Microsoft365GroupsUtility.AddMembers(GraphRequestHelper, Identity.GetGroupId(GraphRequestHelper), Users, RemoveExisting);
26+
Microsoft365GroupsUtility.AddMembers(GraphRequestHelper, Identity.GetGroupId(GraphRequestHelper), Users);
2527
}
2628
}
2729
}

src/Commands/Microsoft365Groups/AddMicrosoft365GroupOwner.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using PnP.PowerShell.Commands.Base;
33
using PnP.PowerShell.Commands.Base.PipeBinds;
44
using PnP.PowerShell.Commands.Utilities;
5+
using System;
56
using System.Management.Automation;
67

78
namespace PnP.PowerShell.Commands.Microsoft365Groups
@@ -16,12 +17,13 @@ public class AddMicrosoft365GroupOwner : PnPGraphCmdlet
1617
[Parameter(Mandatory = true)]
1718
public string[] Users;
1819

20+
[Obsolete("The parameter is obsolete and will be removed in future versions. You can use Clear-PnPMicrosoft365GroupOwner instead.")]
1921
[Parameter(Mandatory = false)]
2022
public SwitchParameter RemoveExisting;
2123

2224
protected override void ExecuteCmdlet()
2325
{
24-
Microsoft365GroupsUtility.AddOwners(GraphRequestHelper, Identity.GetGroupId(GraphRequestHelper), Users, RemoveExisting);
26+
Microsoft365GroupsUtility.AddOwners(GraphRequestHelper, Identity.GetGroupId(GraphRequestHelper), Users);
2527
}
2628
}
2729
}

src/Commands/Utilities/Microsoft365GroupsUtility.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -289,24 +289,24 @@ internal static void PermanentlyDeleteDeletedGroup(ApiRequestHelper requestHelpe
289289
requestHelper.Delete($"v1.0/directory/deleteditems/microsoft.graph.group/{groupId}");
290290
}
291291

292-
internal static void AddOwners(ApiRequestHelper requestHelper, Guid groupId, string[] users, bool removeExisting)
292+
internal static void AddOwners(ApiRequestHelper requestHelper, Guid groupId, string[] users)
293293
{
294-
AddUsersToGroup(requestHelper, "owners", groupId, users, removeExisting);
294+
AddUsersToGroup(requestHelper, "owners", groupId, users);
295295
}
296296

297-
internal static void AddDirectoryOwners(ApiRequestHelper requestHelper, Guid groupId, Guid[] users, bool removeExisting)
297+
internal static void AddDirectoryOwners(ApiRequestHelper requestHelper, Guid groupId, Guid[] users)
298298
{
299-
AddDirectoryObjectsToGroup(requestHelper, "owners", groupId, users, removeExisting);
299+
AddDirectoryObjectsToGroup(requestHelper, "owners", groupId, users);
300300
}
301301

302-
internal static void AddMembers(ApiRequestHelper requestHelper, Guid groupId, string[] users, bool removeExisting)
302+
internal static void AddMembers(ApiRequestHelper requestHelper, Guid groupId, string[] users)
303303
{
304-
AddUsersToGroup(requestHelper, "members", groupId, users, removeExisting);
304+
AddUsersToGroup(requestHelper, "members", groupId, users);
305305
}
306306

307-
internal static void AddDirectoryMembers(ApiRequestHelper requestHelper, Guid groupId, Guid[] users, bool removeExisting)
307+
internal static void AddDirectoryMembers(ApiRequestHelper requestHelper, Guid groupId, Guid[] users)
308308
{
309-
AddDirectoryObjectsToGroup(requestHelper, "members", groupId, users, removeExisting);
309+
AddDirectoryObjectsToGroup(requestHelper, "members", groupId, users);
310310
}
311311

312312
internal static string GetUserGraphUrlForUPN(string upn)
@@ -318,7 +318,7 @@ internal static string GetUserGraphUrlForUPN(string upn)
318318
return $"users/{escapedUpn}";
319319
}
320320

321-
private static void AddUsersToGroup(ApiRequestHelper requestHelper, string groupName, Guid groupId, string[] users, bool removeExisting)
321+
private static void AddUsersToGroup(ApiRequestHelper requestHelper, string groupName, Guid groupId, string[] users)
322322
{
323323
foreach (var user in users)
324324
{
@@ -338,7 +338,7 @@ private static void AddUsersToGroup(ApiRequestHelper requestHelper, string group
338338
}
339339
}
340340

341-
private static void AddDirectoryObjectsToGroup(ApiRequestHelper requestHelper, string groupName, Guid groupId, Guid[] directoryObjects, bool removeExisting)
341+
private static void AddDirectoryObjectsToGroup(ApiRequestHelper requestHelper, string groupName, Guid groupId, Guid[] directoryObjects)
342342
{
343343
foreach (var dirObject in directoryObjects)
344344
{
@@ -456,7 +456,7 @@ internal static void UpdateOwners(ApiRequestHelper requestHelper, Guid groupId,
456456
{
457457
if (existingOwners.FirstOrDefault(o => o.UserPrincipalName == owner) == null)
458458
{
459-
AddOwners(requestHelper, groupId, new string[] { owner }, false);
459+
AddOwners(requestHelper, groupId, new string[] { owner });
460460
}
461461
}
462462
foreach (var existingOwner in existingOwners)
@@ -475,7 +475,7 @@ internal static void UpdateMembersAsync(ApiRequestHelper requestHelper, Guid gro
475475
{
476476
if (existingMembers.FirstOrDefault(o => o.UserPrincipalName == member) == null)
477477
{
478-
AddMembers(requestHelper, groupId, new string[] { member }, false);
478+
AddMembers(requestHelper, groupId, new string[] { member });
479479
}
480480
}
481481
foreach (var existingMember in existingMembers)

0 commit comments

Comments
 (0)