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
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 user@company.com -Group 5

Add the specified user to the SharePoint group with Id 5

### EXAMPLE 3
```powershell
$batch = New-PnPBatch
Add-PnPGroupMember -LoginName user@company.com -Group 5 -Batch $batch
Add-PnPGroupMember -LoginName user1@company.com -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