Skip to content

Commit 23d6bcb

Browse files
gautamdshethGautam Sheth
andauthored
Add Contributors and Managers parameters to New-PnPTermGroup and Set-PnPTermGroup cmdlets (#4567)
Co-authored-by: Gautam Sheth <[email protected]>
1 parent 28ed2f1 commit 23d6bcb

File tree

5 files changed

+141
-7
lines changed

5 files changed

+141
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
3636
- Added `Add-PnPFileSensitivityLabel` which allows for assigning sensitivity labels to SharePoint files [#4538](https://github.com/pnp/powershell/pull/4538)
3737
- Added `-CanSyncHubSitePermissions` parameter to `Set-PnPSite` cmdlet to set value of allowing syncing hub site permissions to this associated site.
3838
- 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)
39+
- Added `-Contributors` and `-Managers` parameters to `New-PnPTermGroup` and `Set-PnPTermGroup` cmdlets.
3940

4041
### Changed
4142

documentation/New-PnPTermGroup.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Creates a taxonomy term group
1616

1717
```powershell
1818
New-PnPTermGroup -Name <String> [-Id <Guid>] [-Description <String>]
19-
[-TermStore <PnP.PowerShell.Commands.Base.PipeBinds.GenericObjectNameIdPipeBind`1[Microsoft.SharePoint.Client.Taxonomy.TermStore]>]
19+
[-TermStore <PnP.PowerShell.Commands.Base.PipeBinds.GenericObjectNameIdPipeBind`1[Microsoft.SharePoint.Client.Taxonomy.TermStore]>] [-Contributors <string []>] [-Managers <string []>]
2020
[-Connection <PnPConnection>]
2121
```
2222

@@ -33,6 +33,13 @@ New-PnPTermGroup -GroupName "Countries"
3333

3434
Creates a new taxonomy term group named "Countries"
3535

36+
### EXAMPLE 2
37+
```powershell
38+
New-PnPTermGroup -GroupName "Countries" -Contributors @("i:0#.f|membership|[email protected]","i:0#.f|membership|[email protected]") -Managers @("i:0#.f|membership|[email protected]","i:0#.f|membership|[email protected]")
39+
```
40+
41+
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.**
42+
3643
## PARAMETERS
3744

3845
### -Connection
@@ -108,6 +115,36 @@ Accept pipeline input: False
108115
Accept wildcard characters: False
109116
```
110117
118+
### -Managers
119+
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.**
120+
121+
```yaml
122+
Type: string[]
123+
Parameter Sets: (All)
124+
Aliases:
125+
126+
Required: False
127+
Position: Named
128+
Default value: None
129+
Accept pipeline input: False
130+
Accept wildcard characters: False
131+
```
132+
133+
### -Contributors
134+
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.**
135+
136+
```yaml
137+
Type: string[]
138+
Parameter Sets: (All)
139+
Aliases:
140+
141+
Required: False
142+
Position: Named
143+
Default value: None
144+
Accept pipeline input: False
145+
Accept wildcard characters: False
146+
```
147+
111148
## RELATED LINKS
112149
113150
[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)

documentation/Set-PnPTermGroup.md

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Updates an existing term group.
1616

1717
```powershell
1818
Set-PnPTermGroup -Identity <TaxonomyTermGroupPipeBind> [-Name <String>] [-Description <String>]
19-
[-TermStore <TaxonomyTermStorePipeBind>] [-Connection <PnPConnection>]
19+
[-TermStore <TaxonomyTermStorePipeBind>] [-Connection <PnPConnection>] [-Contributors <string []>] [-Managers <string []>]
2020
```
2121

2222
## DESCRIPTION
@@ -31,8 +31,14 @@ Set-PnPTermGroup -Identity "Departments" -Name "Company Units"
3131

3232
Renames the Departments termgroup to "Company Units".
3333

34-
## PARAMETERS
34+
### Example 2
35+
```powershell
36+
Set-PnPTermGroup -Identity "Departments" -Name "Company Units" -Contributors @("i:0#.f|membership|[email protected]","i:0#.f|membership|[email protected]") -Managers @("i:0#.f|membership|[email protected]","i:0#.f|membership|[email protected]")
37+
```
3538

39+
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.**
40+
41+
## PARAMETERS
3642

3743
### -Description
3844
Optional description of the term group.
@@ -109,6 +115,36 @@ Accept pipeline input: False
109115
Accept wildcard characters: False
110116
```
111117
118+
### -Managers
119+
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.**
120+
121+
```yaml
122+
Type: string[]
123+
Parameter Sets: (All)
124+
Aliases:
125+
126+
Required: False
127+
Position: Named
128+
Default value: None
129+
Accept pipeline input: False
130+
Accept wildcard characters: False
131+
```
132+
133+
### -Contributors
134+
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.**
135+
136+
```yaml
137+
Type: string[]
138+
Parameter Sets: (All)
139+
Aliases:
140+
141+
Required: False
142+
Position: Named
143+
Default value: None
144+
Accept pipeline input: False
145+
Accept wildcard characters: False
146+
```
147+
112148
113149
## RELATED LINKS
114150

src/Commands/Taxonomy/NewTermGroup.cs

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
using System;
2-
using System.Management.Automation;
3-
using Microsoft.SharePoint.Client;
1+
using Microsoft.SharePoint.Client;
42
using Microsoft.SharePoint.Client.Taxonomy;
5-
63
using PnP.PowerShell.Commands.Base.PipeBinds;
4+
using System;
5+
using System.Management.Automation;
76

87
namespace PnP.PowerShell.Commands.Taxonomy
98
{
@@ -25,6 +24,12 @@ public class NewTermGroup : PnPSharePointCmdlet
2524
[Alias("TermStoreName")]
2625
public TaxonomyTermStorePipeBind TermStore;
2726

27+
[Parameter(Mandatory = false)]
28+
public string[] Contributors;
29+
30+
[Parameter(Mandatory = false)]
31+
public string[] Managers;
32+
2833
protected override void ExecuteCmdlet()
2934
{
3035
var taxonomySession = TaxonomySession.GetTaxonomySession(ClientContext);
@@ -40,6 +45,34 @@ protected override void ExecuteCmdlet()
4045
}
4146
// Create Group
4247
var group = termStore.CreateTermGroup(Name, Id, Description);
48+
bool updateRequired = false;
49+
if (Contributors != null && Contributors.Length > 0)
50+
{
51+
foreach (var contributor in Contributors)
52+
{
53+
group.AddContributor(contributor);
54+
}
55+
updateRequired = true;
56+
}
57+
if (Managers != null && Managers.Length > 0)
58+
{
59+
foreach (var manager in Managers)
60+
{
61+
group.AddGroupManager(manager);
62+
}
63+
updateRequired = true;
64+
}
65+
66+
if (updateRequired)
67+
{
68+
termStore.CommitAll();
69+
ClientContext.Load(group, group => group.GroupManagerPrincipalNames, group => group.ContributorPrincipalNames, group => group.Name, group => group.Description, group => group.Id);
70+
ClientContext.Load(termStore);
71+
ClientContext.ExecuteQueryRetry();
72+
73+
taxonomySession.UpdateCache();
74+
taxonomySession.Context.ExecuteQueryRetry();
75+
}
4376

4477
WriteObject(group);
4578
}

src/Commands/Taxonomy/SetTermGroup.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ public class SetTermGroup : PnPSharePointCmdlet
2121
[Parameter(Mandatory = false)]
2222
public string Description { get; set; }
2323

24+
[Parameter(Mandatory = false)]
25+
public string[] Contributors { get; set; }
26+
27+
[Parameter(Mandatory = false)]
28+
public string[] Managers { get; set; }
29+
2430
protected override void ExecuteCmdlet()
2531
{
2632
var taxonomySession = TaxonomySession.GetTaxonomySession(ClientContext);
@@ -61,10 +67,31 @@ protected override void ExecuteCmdlet()
6167
group.Description = Description;
6268
updateRequired = true;
6369
}
70+
if (Contributors != null && Contributors.Length > 0)
71+
{
72+
foreach (var contributor in Contributors)
73+
{
74+
group.AddContributor(contributor);
75+
}
76+
updateRequired = true;
77+
}
78+
if (Managers != null && Managers.Length > 0)
79+
{
80+
foreach (var manager in Managers)
81+
{
82+
group.AddGroupManager(manager);
83+
}
84+
updateRequired = true;
85+
}
6486
if (updateRequired)
6587
{
6688
termStore.CommitAll();
89+
ClientContext.Load(group, group => group.GroupManagerPrincipalNames, group => group.ContributorPrincipalNames, group => group.Name, group => group.Description, group => group.Id);
90+
ClientContext.Load(termStore);
6791
ClientContext.ExecuteQueryRetry();
92+
93+
taxonomySession.UpdateCache();
94+
taxonomySession.Context.ExecuteQueryRetry();
6895
}
6996
WriteObject(group);
7097
}

0 commit comments

Comments
 (0)