diff --git a/CHANGELOG.md b/CHANGELOG.md index 48ccad069..146262433 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/documentation/Add-PnPGroupMember.md b/documentation/Add-PnPGroupMember.md index ad8bba906..345e35405 100644 --- a/documentation/Add-PnPGroupMember.md +++ b/documentation/Add-PnPGroupMember.md @@ -26,6 +26,12 @@ Add-PnPGroupMember -Group -EmailAddress [-SendEmail] [- [-Connection ] ``` +### Batched +```powershell +Add-PnPGroupMember -LoginName -Group + [-Connection ] -Batch +``` + ## DESCRIPTION Allows to add new user to SharePoint group. The SharePoint group may be specified either by id, name or related object. @@ -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 @@ -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 diff --git a/src/Commands/Principals/AddGroupMember.cs b/src/Commands/Principals/AddGroupMember.cs index 8cf05ccba..6e00ecd1d 100644 --- a/src/Commands/Principals/AddGroupMember.cs +++ b/src/Commands/Principals/AddGroupMember.cs @@ -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 { @@ -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; @@ -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) @@ -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); + } } } }