From 18c0f6c44817fadc359cfdb3d037d590ebc9466b Mon Sep 17 00:00:00 2001 From: Gautam Sheth Date: Thu, 21 Nov 2024 22:10:42 +0200 Subject: [PATCH] Add Contributors and Managers parameters to New-PnPTermGroup and Set-PnPTermGroup cmdlets --- CHANGELOG.md | 1 + documentation/New-PnPTermGroup.md | 39 ++++++++++++++++++++++++- documentation/Set-PnPTermGroup.md | 40 ++++++++++++++++++++++++-- src/Commands/Taxonomy/NewTermGroup.cs | 41 ++++++++++++++++++++++++--- src/Commands/Taxonomy/SetTermGroup.cs | 27 ++++++++++++++++++ 5 files changed, 141 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 92a8a039b..be2666d2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Added `Add-PnPFileSensitivityLabel` which allows for assigning sensitivity labels to SharePoint files [#4538](https://github.com/pnp/powershell/pull/4538) - Added `-CanSyncHubSitePermissions` parameter to `Set-PnPSite` cmdlet to set value of allowing syncing hub site permissions to this associated site. - Added `Get-PnPProfileCardProperty`, `New-PnPProfileCardProperty` and `Remove-PnPProfileCardProperty` cmdlets to manage showing additional properties on the Microsoft 365 user profile [#4548](https://github.com/pnp/powershell/pull/4548) +- Added `-Contributors` and `-Managers` parameters to `New-PnPTermGroup` and `Set-PnPTermGroup` cmdlets. ### Changed diff --git a/documentation/New-PnPTermGroup.md b/documentation/New-PnPTermGroup.md index f01da50ad..d8986657d 100644 --- a/documentation/New-PnPTermGroup.md +++ b/documentation/New-PnPTermGroup.md @@ -16,7 +16,7 @@ Creates a taxonomy term group ```powershell New-PnPTermGroup -Name [-Id ] [-Description ] - [-TermStore ] + [-TermStore ] [-Contributors ] [-Managers ] [-Connection ] ``` @@ -33,6 +33,13 @@ New-PnPTermGroup -GroupName "Countries" Creates a new taxonomy term group named "Countries" +### EXAMPLE 2 +```powershell +New-PnPTermGroup -GroupName "Countries" -Contributors @("i:0#.f|membership|pradeepg@gautamdev.onmicrosoft.com","i:0#.f|membership|adelev@gautamdev.onmicrosoft.com") -Managers @("i:0#.f|membership|alexw@gautamdev.onmicrosoft.com","i:0#.f|membership|diegos@gautamdev.onmicrosoft.com") +``` + +Creates a new taxonomy term group named "Countries" and sets the users as contributors and managers of the term group. **The user names for contributors and managers need to be encoded claim for the specified login names.** + ## PARAMETERS ### -Connection @@ -108,6 +115,36 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -Managers +The manager of the term group who can create/edit term sets in the group as well as add/remove contributors. **The user names for managers need to be encoded claim for the specified login names.** + +```yaml +Type: string[] +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Contributors +The contributor to the term group who can create/edit term sets in the group. **The user names for contributors need to be encoded claim for the specified login names.** + +```yaml +Type: string[] +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ## RELATED LINKS [Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp) diff --git a/documentation/Set-PnPTermGroup.md b/documentation/Set-PnPTermGroup.md index e231605ff..9cea0b353 100644 --- a/documentation/Set-PnPTermGroup.md +++ b/documentation/Set-PnPTermGroup.md @@ -16,7 +16,7 @@ Updates an existing term group. ```powershell Set-PnPTermGroup -Identity [-Name ] [-Description ] - [-TermStore ] [-Connection ] + [-TermStore ] [-Connection ] [-Contributors ] [-Managers ] ``` ## DESCRIPTION @@ -31,8 +31,14 @@ Set-PnPTermGroup -Identity "Departments" -Name "Company Units" Renames the Departments termgroup to "Company Units". -## PARAMETERS +### Example 2 +```powershell +Set-PnPTermGroup -Identity "Departments" -Name "Company Units" -Contributors @("i:0#.f|membership|pradeepg@gautamdev.onmicrosoft.com","i:0#.f|membership|adelev@gautamdev.onmicrosoft.com") -Managers @("i:0#.f|membership|alexw@gautamdev.onmicrosoft.com","i:0#.f|membership|diegos@gautamdev.onmicrosoft.com") +``` +Renames the Departments termgroup to "Company Units" and adds contributors and managers of the term group. **The user names for contributors and managers need to be encoded claim for the specified login names.** + +## PARAMETERS ### -Description Optional description of the term group. @@ -109,6 +115,36 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -Managers +The manager of the term group who can create/edit term sets in the group as well as add/remove contributors. **The user names for managers need to be encoded claim for the specified login names.** + +```yaml +Type: string[] +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Contributors +The contributor to the term group who can create/edit term sets in the group. **The user names for contributors need to be encoded claim for the specified login names.** + +```yaml +Type: string[] +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ## RELATED LINKS diff --git a/src/Commands/Taxonomy/NewTermGroup.cs b/src/Commands/Taxonomy/NewTermGroup.cs index 41f4eeed9..32917aa30 100644 --- a/src/Commands/Taxonomy/NewTermGroup.cs +++ b/src/Commands/Taxonomy/NewTermGroup.cs @@ -1,9 +1,8 @@ -using System; -using System.Management.Automation; -using Microsoft.SharePoint.Client; +using Microsoft.SharePoint.Client; using Microsoft.SharePoint.Client.Taxonomy; - using PnP.PowerShell.Commands.Base.PipeBinds; +using System; +using System.Management.Automation; namespace PnP.PowerShell.Commands.Taxonomy { @@ -25,6 +24,12 @@ public class NewTermGroup : PnPSharePointCmdlet [Alias("TermStoreName")] public TaxonomyTermStorePipeBind TermStore; + [Parameter(Mandatory = false)] + public string[] Contributors; + + [Parameter(Mandatory = false)] + public string[] Managers; + protected override void ExecuteCmdlet() { var taxonomySession = TaxonomySession.GetTaxonomySession(ClientContext); @@ -40,6 +45,34 @@ protected override void ExecuteCmdlet() } // Create Group var group = termStore.CreateTermGroup(Name, Id, Description); + bool updateRequired = false; + if (Contributors != null && Contributors.Length > 0) + { + foreach (var contributor in Contributors) + { + group.AddContributor(contributor); + } + updateRequired = true; + } + if (Managers != null && Managers.Length > 0) + { + foreach (var manager in Managers) + { + group.AddGroupManager(manager); + } + updateRequired = true; + } + + if (updateRequired) + { + termStore.CommitAll(); + ClientContext.Load(group, group => group.GroupManagerPrincipalNames, group => group.ContributorPrincipalNames, group => group.Name, group => group.Description, group => group.Id); + ClientContext.Load(termStore); + ClientContext.ExecuteQueryRetry(); + + taxonomySession.UpdateCache(); + taxonomySession.Context.ExecuteQueryRetry(); + } WriteObject(group); } diff --git a/src/Commands/Taxonomy/SetTermGroup.cs b/src/Commands/Taxonomy/SetTermGroup.cs index 64bcbc2ec..b652ce462 100644 --- a/src/Commands/Taxonomy/SetTermGroup.cs +++ b/src/Commands/Taxonomy/SetTermGroup.cs @@ -21,6 +21,12 @@ public class SetTermGroup : PnPSharePointCmdlet [Parameter(Mandatory = false)] public string Description { get; set; } + [Parameter(Mandatory = false)] + public string[] Contributors { get; set; } + + [Parameter(Mandatory = false)] + public string[] Managers { get; set; } + protected override void ExecuteCmdlet() { var taxonomySession = TaxonomySession.GetTaxonomySession(ClientContext); @@ -61,10 +67,31 @@ protected override void ExecuteCmdlet() group.Description = Description; updateRequired = true; } + if (Contributors != null && Contributors.Length > 0) + { + foreach (var contributor in Contributors) + { + group.AddContributor(contributor); + } + updateRequired = true; + } + if (Managers != null && Managers.Length > 0) + { + foreach (var manager in Managers) + { + group.AddGroupManager(manager); + } + updateRequired = true; + } if (updateRequired) { termStore.CommitAll(); + ClientContext.Load(group, group => group.GroupManagerPrincipalNames, group => group.ContributorPrincipalNames, group => group.Name, group => group.Description, group => group.Id); + ClientContext.Load(termStore); ClientContext.ExecuteQueryRetry(); + + taxonomySession.UpdateCache(); + taxonomySession.Context.ExecuteQueryRetry(); } WriteObject(group); }