From 7be0b8beb7d1feff3339856a12deaa6020c928db Mon Sep 17 00:00:00 2001 From: Gautam Sheth Date: Wed, 27 Dec 2023 10:46:52 +0200 Subject: [PATCH 1/2] Feature #3612 - Added Batch parameter to Add-PnPGroupMember cmdlet --- CHANGELOG.md | 1 + documentation/Add-PnPGroupMember.md | 29 +++++++++++++++++++++++ src/Commands/Principals/AddGroupMember.cs | 17 ++++++++++++- 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c4cd729dc..08b114a4f 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. ### Contributors 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); + } } } } From cb28c792b5d074d393f3b47c7b17cebcee8fe354 Mon Sep 17 00:00:00 2001 From: Gautam Sheth Date: Wed, 27 Dec 2023 10:48:01 +0200 Subject: [PATCH 2/2] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 08b114a4f..b141f0675 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +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. +- 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) ### Contributors