Skip to content

Commit 62be9c0

Browse files
kunj-sanganikunj.sanganigautamdsheth
authored
Adding Move-PnPTerm and Move-PnPTermSet commands (#2989)
* Adding Move-PnPTerm and Move-PnPTermSet commands * Changed the name of the parameters --------- Co-authored-by: kunj.sangani <kunj.sangani@gmail.com> Co-authored-by: Gautam Sheth <gautamdsheth@outlook.com>
1 parent c56d781 commit 62be9c0

File tree

4 files changed

+433
-0
lines changed

4 files changed

+433
-0
lines changed

documentation/Move-PnPTerm.md

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
---
2+
Module Name: PnP.PowerShell
3+
title: Move-PnPTerm
4+
schema: 2.0.0
5+
applicable: SharePoint Online
6+
external help file: PnP.PowerShell.dll-Help.xml
7+
online version: https://pnp.github.io/powershell/cmdlets/Move-PnPTerm.html
8+
---
9+
10+
# Move-PnPTerm
11+
12+
## SYNOPSIS
13+
14+
Moves a taxonomy term to another term set or term
15+
16+
## SYNTAX
17+
18+
### Move to term set by Term Id
19+
```
20+
Move-PnPTerm -Identity d67966b0-3b60-4331-8dc4-0b5a2ca730fc -TargetTermSet 95e13729-3ccf-4ec8-998c-78e9ef1daa0b -TargetTermGroup b2645144-5757-4cd7-b7f9-e5d24757addf
21+
```
22+
### Move to term set by Term Name
23+
```
24+
Move-PnPTerm -Identity "Test" -TargetTermSet "TestTermSet1" -TermSet "OperationLevel-1 Test" -TermGroup "FromPowerAutomate" -TargetTermGroup "TestingGroup"
25+
```
26+
### Move to term
27+
```
28+
Move-PnPTerm -Identity d67966b0-3b60-4331-8dc4-0b5a2ca730fc -TargetTerm 2ad90b20-b5c0-4544-ac64-25e32d51fa3b -MoveToTerm
29+
```
30+
31+
## DESCRIPTION
32+
33+
This cmdlet moves a taxonomy term to another term set or term
34+
35+
## EXAMPLES
36+
37+
### Example 1
38+
```powershell
39+
Move-PnPTerm -Identity d67966b0-3b60-4331-8dc4-0b5a2ca730fc -TargetTermSet 95e13729-3ccf-4ec8-998c-78e9ef1daa0b -TargetTermGroup b2645144-5757-4cd7-b7f9-e5d24757addf
40+
```
41+
42+
Moves term by id to term set.
43+
44+
### Example 2
45+
```powershell
46+
Move-PnPTerm -Identity "Test" -TargetTermSet "TestTermSet1" -TermSet "OperationLevel-1 Test" -TermGroup "FromPowerAutomate" -TargetTermGroup "TestingGroup"
47+
```
48+
49+
Moves term by name to term set.
50+
51+
### Example 3
52+
```powershell
53+
Move-PnPTerm -Identity d67966b0-3b60-4331-8dc4-0b5a2ca730fc -TargetTerm 2ad90b20-b5c0-4544-ac64-25e32d51fa3b -MoveToTerm
54+
```
55+
56+
Moves a term to another term by its identifier.
57+
58+
## PARAMETERS
59+
60+
### -Identity
61+
The identifier of the term that needs to be moved, either in the form of its name or its GUID
62+
63+
```yaml
64+
Type: TaxonomyTermPipeBind
65+
Parameter Sets: (All)
66+
Aliases: Term
67+
68+
Required: True
69+
Position: 0
70+
Default value: None
71+
Accept pipeline input: True (ByValue)
72+
Accept wildcard characters: False
73+
```
74+
75+
### -TargetTermSet
76+
The identifier of the term set where the term needs to be moved, either in the form of its name or its GUID
77+
78+
```yaml
79+
Type: TaxonomyTermSetPipeBind
80+
Parameter Sets: By Term Id, By Term Name
81+
Aliases:
82+
83+
Required: True
84+
Position: 0
85+
Default value: None
86+
Accept pipeline input: True (ByValue)
87+
Accept wildcard characters: False
88+
```
89+
90+
### -TargetTermGroup
91+
The identifier of the term group where the term needs to be moved, either in the form of its name or its GUID
92+
93+
```yaml
94+
Type: TaxonomyTermGroupPipeBind
95+
Parameter Sets: By Term Id, By Term Name
96+
Aliases:
97+
98+
Required: True
99+
Position: 0
100+
Default value: None
101+
Accept pipeline input: True (ByValue)
102+
Accept wildcard characters: False
103+
```
104+
105+
### -TermSet
106+
The identifier of the term set where the term is present, in the form of its name
107+
108+
```yaml
109+
Type: TaxonomyTermSetPipeBind
110+
Parameter Sets: By Term Name
111+
Aliases:
112+
113+
Required: True
114+
Position: 0
115+
Default value: None
116+
Accept pipeline input: True (ByValue)
117+
Accept wildcard characters: False
118+
```
119+
120+
### -TermGroup
121+
The identifier of the term set where the term group is present, in the form of its name
122+
123+
```yaml
124+
Type: TaxonomyTermGroupPipeBind
125+
Parameter Sets: By Term Name
126+
Aliases:
127+
128+
Required: True
129+
Position: 0
130+
Default value: None
131+
Accept pipeline input: True (ByValue)
132+
Accept wildcard characters: False
133+
```
134+
135+
### -TargetTerm
136+
The identifier of the term where the term needs to be moved, in the form of its GUID
137+
138+
```yaml
139+
Type: TaxonomyTermPipeBind
140+
Parameter Sets: Move To Term
141+
Aliases:
142+
143+
Required: True
144+
Position: 0
145+
Default value: None
146+
Accept pipeline input: True (ByValue)
147+
Accept wildcard characters: False
148+
```
149+
150+
### -MoveToTerm
151+
To be provided if the term needs to be moved to another term
152+
153+
```yaml
154+
Type: SwitchParameter
155+
Parameter Sets: Move To Term
156+
157+
Required: True
158+
Position: Named
159+
Default value: None
160+
Accept pipeline input: False
161+
Accept wildcard characters: False
162+
```
163+
164+
### -TermStore
165+
Term store to use; if not specified the default term store is used.
166+
167+
```yaml
168+
Type: TaxonomyTermStorePipeBind
169+
Parameter Sets: (All)
170+
Aliases:
171+
172+
Required: False
173+
Position: Named
174+
Default value: None
175+
Accept pipeline input: False
176+
Accept wildcard characters: False
177+
```

documentation/Move-PnPTermSet.md

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
---
2+
Module Name: PnP.PowerShell
3+
title: Move-PnPTermSet
4+
schema: 2.0.0
5+
applicable: SharePoint Online
6+
external help file: PnP.PowerShell.dll-Help.xml
7+
online version: https://pnp.github.io/powershell/cmdlets/Move-PnPTermSet.html
8+
---
9+
10+
# Move-PnPTermSet
11+
12+
## SYNOPSIS
13+
14+
Moves taxonomy term set from one term group to another
15+
16+
## SYNTAX
17+
18+
### By Term Id
19+
```
20+
Move-PnPTermSet -Identity <Guid> -TermGroup <Guid> -TargetTermGroup <Guid> [-TermStore <TaxonomyTermStorePipeBind>]
21+
```
22+
23+
### By Term Name
24+
```
25+
Move-PnPTermSet -Identity <String> -TermGroup <String> -TargetTermGroup <String> [-TermStore <TaxonomyTermStorePipeBind>]
26+
```
27+
28+
## DESCRIPTION
29+
This cmdlet moves taxonomy term set from one term group to another.
30+
31+
## EXAMPLES
32+
33+
### Example 1
34+
```powershell
35+
Move-PnPTermSet -Identity 81e0a4b8-701d-459c-ad61-a1c7a81810ff -TermGroup 17e16b98-a8c2-4db6-a860-5c42dbc818f4 -TargetTermGroup cf33d1cd-42d8-431c-9e43-3d8dab9ea8fd
36+
```
37+
38+
Moves term set by id.
39+
40+
### Example 2
41+
```powershell
42+
Move-PnPTermSet -Identity "OperationLevel-1 Test" -TermGroup "FromPowerAutomate" -TargetTermGroup "TargetTermGroup"
43+
```
44+
45+
Moves term set by name.
46+
47+
## PARAMETERS
48+
49+
### -Identity
50+
The identifier of the term set that needs to be moved, either in the form of its name or its GUID
51+
52+
```yaml
53+
Type: TaxonomyTermSetPipeBind
54+
Parameter Sets: (All)
55+
Aliases: TermSet
56+
57+
Required: True
58+
Position: 0
59+
Default value: None
60+
Accept pipeline input: True (ByValue)
61+
Accept wildcard characters: False
62+
```
63+
64+
### -TermGroup
65+
The identifier, either in the form of the term group's name or its GUID, where the term set is currently located before being moved.
66+
67+
```yaml
68+
Type: TaxonomyTermGroupPipeBind
69+
Parameter Sets: (All)
70+
Aliases:
71+
72+
Required: True
73+
Position: 0
74+
Default value: None
75+
Accept pipeline input: True (ByValue)
76+
Accept wildcard characters: False
77+
```
78+
79+
### -TargetTermGroup
80+
The identifier, either in the form of the term group's name or its GUID, indicating the destination where the term set should be relocated.
81+
82+
```yaml
83+
Type: TaxonomyTermGroupPipeBind
84+
Parameter Sets: (All)
85+
Aliases:
86+
87+
Required: True
88+
Position: 0
89+
Default value: None
90+
Accept pipeline input: True (ByValue)
91+
Accept wildcard characters: False
92+
```
93+
94+
### -TermStore
95+
Term store to use; if not specified the default term store is used.
96+
97+
```yaml
98+
Type: TaxonomyTermStorePipeBind
99+
Parameter Sets: (All)
100+
Aliases:
101+
102+
Required: False
103+
Position: Named
104+
Default value: None
105+
Accept pipeline input: False
106+
Accept wildcard characters: False
107+
```

src/Commands/Taxonomy/MoveTerm.cs

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
using Microsoft.SharePoint.Client;
2+
using Microsoft.SharePoint.Client.Taxonomy;
3+
using PnP.PowerShell.Commands.Base.PipeBinds;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Management.Automation;
8+
using System.Text;
9+
using System.Threading.Tasks;
10+
11+
namespace PnP.PowerShell.Commands.Taxonomy
12+
{
13+
[Cmdlet(VerbsCommon.Move, "PnPTerm")]
14+
public class MoveTerm : PnPSharePointCmdlet
15+
{
16+
private const string ParameterSet_TERMID = "By Term Id";
17+
private const string ParameterSet_TERMNAME = "By Term Name";
18+
private const string ParameterSet_MoveToTerm = "Move To Term";
19+
20+
[Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = ParameterSet_MoveToTerm)]
21+
[Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = ParameterSet_TERMID)]
22+
[Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = ParameterSet_TERMNAME)]
23+
[Alias("Term")]
24+
public TaxonomyTermPipeBind Identity;
25+
26+
[Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = ParameterSet_TERMID)]
27+
[Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = ParameterSet_TERMNAME)]
28+
public TaxonomyTermSetPipeBind TargetTermSet;
29+
30+
[Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = ParameterSet_TERMID)]
31+
[Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = ParameterSet_TERMNAME)]
32+
public TaxonomyTermGroupPipeBind TargetTermGroup;
33+
34+
[Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = ParameterSet_TERMNAME)]
35+
public TaxonomyTermSetPipeBind TermSet;
36+
37+
[Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = ParameterSet_TERMNAME)]
38+
public TaxonomyTermGroupPipeBind TermGroup;
39+
40+
[Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = ParameterSet_MoveToTerm)]
41+
public TaxonomyTermPipeBind TargetTerm;
42+
43+
[Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = ParameterSet_MoveToTerm)]
44+
public SwitchParameter MoveToTerm;
45+
46+
[Parameter(Mandatory = false, ParameterSetName = ParameterAttribute.AllParameterSets)]
47+
[Alias("TermStoreName")]
48+
public TaxonomyTermStorePipeBind TermStore;
49+
50+
protected override void ExecuteCmdlet()
51+
{
52+
var taxonomySession = TaxonomySession.GetTaxonomySession(ClientContext);
53+
// Get Term Store
54+
TermStore termStore = null;
55+
if (TermStore == null)
56+
{
57+
termStore = taxonomySession.GetDefaultSiteCollectionTermStore();
58+
}
59+
else
60+
{
61+
termStore = TermStore.GetTermStore(taxonomySession);
62+
}
63+
if (MoveToTerm.ToBool())
64+
{
65+
Term sourceterm = Identity.GetTerm(ClientContext, termStore, null, false, null);
66+
Term destinationterm = TargetTerm.GetTerm(ClientContext, termStore, null, false, null);
67+
68+
sourceterm.Move(destinationterm);
69+
ClientContext.ExecuteQueryRetry();
70+
}
71+
else
72+
{
73+
Term term = null;
74+
TermSet destinationtermSet = null;
75+
if (ParameterSetName == ParameterSet_TERMID)
76+
{
77+
term = Identity.GetTerm(ClientContext, termStore, null, false, null);
78+
TermGroup destinationtermGroup = TargetTermGroup.GetGroup(termStore);
79+
destinationtermSet = TargetTermSet.GetTermSet(destinationtermGroup);
80+
}
81+
else
82+
{
83+
TermGroup termGroup = TermGroup.GetGroup(termStore);
84+
TermSet termSet = TermSet.GetTermSet(termGroup);
85+
term = Identity.GetTerm(ClientContext, termStore, termSet, false, null);
86+
TermGroup destinationtermGroup = TargetTermGroup.GetGroup(termStore);
87+
destinationtermSet = TargetTermSet.GetTermSet(destinationtermGroup);
88+
}
89+
90+
term.Move(destinationtermSet);
91+
ClientContext.ExecuteQueryRetry();
92+
}
93+
}
94+
}
95+
}

0 commit comments

Comments
 (0)