Skip to content

Commit

Permalink
Feature #3612 - Added Batch parameter to Add-PnPGroupMember cmdlet (#…
Browse files Browse the repository at this point in the history
…3651)

* Feature #3612 - Added Batch parameter to Add-PnPGroupMember cmdlet

* Update CHANGELOG.md

---------

Co-authored-by: Gautam Sheth <[email protected]>
  • Loading branch information
gautamdsheth and Gautam Sheth authored Jan 19, 2024
1 parent 083de68 commit 451a3c6
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Added `Convert-PnPFile` cmdlet which allows for a file to be converted to from one format to another. [#3435](https://github.com/pnp/powershell/pull/3435) & [#3643](https://github.com/pnp/powershell/pull/3643)
- Added `Merge-PnPTerm` cmdlet which allows merging of one term into another. [#3638](https://github.com/pnp/powershell/pull/3638)
- Added `Get-PnPDeletedContainer` cmdlet which returns a list of all deleted Containers in the recycle bin. [#3648](https://github.com/pnp/powershell/pull/3648)
- Added `-Batch` parameter to `Add-PnPGroupMember` cmdlet which allows adding members to a SharePoint group in a batch. [#3651](https://github.com/pnp/powershell/pull/3651)=======
- Added `Get-PnPContainerTypeConfiguration` cmdlet which fetches the container type configuration values. [#3660](https://github.com/pnp/powershell/pull/3660)
- Added `-AppBypassInformationBarriers` and `-DefaultOneDriveInformationBarrierMode` parameters to `Set-PnPTenant` cmdlet. [#3679](https://github.com/pnp/powershell/pull/3679)

Expand Down
29 changes: 29 additions & 0 deletions documentation/Add-PnPGroupMember.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ Add-PnPGroupMember -Group <GroupPipeBind> -EmailAddress <String> [-SendEmail] [-
[-Connection <PnPConnection>]
```

### Batched
```powershell
Add-PnPGroupMember -LoginName <String> -Group <GroupPipeBind>
[-Connection <PnPConnection>] -Batch <PnPBatch>
```

## DESCRIPTION

Allows to add new user to SharePoint group. The SharePoint group may be specified either by id, name or related object.
Expand All @@ -46,6 +52,16 @@ Add-PnPGroupMember -LoginName [email protected] -Group 5

Add the specified user to the SharePoint group with Id 5

### EXAMPLE 3
```powershell
$batch = New-PnPBatch
Add-PnPGroupMember -LoginName [email protected] -Group 5 -Batch $batch
Add-PnPGroupMember -LoginName [email protected] -Group 5 -Batch $batch
Invoke-PnPBatch $batch
```

Add the specified users to the SharePoint group with Id 5 in a batch.

## PARAMETERS

### -Connection
Expand Down Expand Up @@ -130,6 +146,19 @@ Accept pipeline input: False
Accept wildcard characters: False
```
### -Batch
```yaml
Type: PnPBatch
Parameter Sets: Batched

Required: True
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
## RELATED LINKS
Expand Down
17 changes: 16 additions & 1 deletion src/Commands/Principals/AddGroupMember.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Management.Automation;
using Microsoft.SharePoint.Client;
using PnP.PowerShell.Commands.Base.PipeBinds;
using PnP.PowerShell.Commands.Model;

namespace PnP.PowerShell.Commands.Principals
{
Expand All @@ -10,12 +11,15 @@ public class AddGroupMember : PnPWebCmdlet
{
private const string ParameterSet_INTERNAL = "Internal";
private const string ParameterSet_EXTERNAL = "External";
private const string ParameterSet_BATCHED = "Batched";

[Parameter(Mandatory = true, ParameterSetName = ParameterSet_INTERNAL)]
[Parameter(Mandatory = true, ParameterSetName = ParameterSet_BATCHED)]
public string LoginName;

[Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = ParameterSet_INTERNAL)]
[Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = ParameterSet_EXTERNAL)]
[Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = ParameterSet_BATCHED)]
[Alias("Identity")]
public GroupPipeBind Group;

Expand All @@ -28,6 +32,9 @@ public class AddGroupMember : PnPWebCmdlet
[Parameter(Mandatory = false, ParameterSetName = ParameterSet_EXTERNAL)]
public string EmailBody = "Site shared with you.";

[Parameter(Mandatory = true, ParameterSetName = ParameterSet_BATCHED)]
public PnPBatch Batch;

protected override void ExecuteCmdlet()
{
if (ParameterSetName == ParameterSet_EXTERNAL)
Expand All @@ -39,7 +46,15 @@ protected override void ExecuteCmdlet()
{
var group = Group.GetGroup(PnPContext);
var user = PnPContext.Web.EnsureUser(LoginName);
group.AddUser(user.LoginName);

if (ParameterSetName == ParameterSet_BATCHED)
{
group.AddUserBatch(Batch.Batch, user.LoginName);
}
else
{
group.AddUser(user.LoginName);
}
}
}
}
Expand Down

0 comments on commit 451a3c6

Please sign in to comment.