-
Notifications
You must be signed in to change notification settings - Fork 361
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
1 parent
c56d781
commit 62be9c0
Showing
4 changed files
with
433 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
--- | ||
Module Name: PnP.PowerShell | ||
title: Move-PnPTerm | ||
schema: 2.0.0 | ||
applicable: SharePoint Online | ||
external help file: PnP.PowerShell.dll-Help.xml | ||
online version: https://pnp.github.io/powershell/cmdlets/Move-PnPTerm.html | ||
--- | ||
|
||
# Move-PnPTerm | ||
|
||
## SYNOPSIS | ||
|
||
Moves a taxonomy term to another term set or term | ||
|
||
## SYNTAX | ||
|
||
### Move to term set by Term Id | ||
``` | ||
Move-PnPTerm -Identity d67966b0-3b60-4331-8dc4-0b5a2ca730fc -TargetTermSet 95e13729-3ccf-4ec8-998c-78e9ef1daa0b -TargetTermGroup b2645144-5757-4cd7-b7f9-e5d24757addf | ||
``` | ||
### Move to term set by Term Name | ||
``` | ||
Move-PnPTerm -Identity "Test" -TargetTermSet "TestTermSet1" -TermSet "OperationLevel-1 Test" -TermGroup "FromPowerAutomate" -TargetTermGroup "TestingGroup" | ||
``` | ||
### Move to term | ||
``` | ||
Move-PnPTerm -Identity d67966b0-3b60-4331-8dc4-0b5a2ca730fc -TargetTerm 2ad90b20-b5c0-4544-ac64-25e32d51fa3b -MoveToTerm | ||
``` | ||
|
||
## DESCRIPTION | ||
|
||
This cmdlet moves a taxonomy term to another term set or term | ||
|
||
## EXAMPLES | ||
|
||
### Example 1 | ||
```powershell | ||
Move-PnPTerm -Identity d67966b0-3b60-4331-8dc4-0b5a2ca730fc -TargetTermSet 95e13729-3ccf-4ec8-998c-78e9ef1daa0b -TargetTermGroup b2645144-5757-4cd7-b7f9-e5d24757addf | ||
``` | ||
|
||
Moves term by id to term set. | ||
|
||
### Example 2 | ||
```powershell | ||
Move-PnPTerm -Identity "Test" -TargetTermSet "TestTermSet1" -TermSet "OperationLevel-1 Test" -TermGroup "FromPowerAutomate" -TargetTermGroup "TestingGroup" | ||
``` | ||
|
||
Moves term by name to term set. | ||
|
||
### Example 3 | ||
```powershell | ||
Move-PnPTerm -Identity d67966b0-3b60-4331-8dc4-0b5a2ca730fc -TargetTerm 2ad90b20-b5c0-4544-ac64-25e32d51fa3b -MoveToTerm | ||
``` | ||
|
||
Moves a term to another term by its identifier. | ||
|
||
## PARAMETERS | ||
|
||
### -Identity | ||
The identifier of the term that needs to be moved, either in the form of its name or its GUID | ||
|
||
```yaml | ||
Type: TaxonomyTermPipeBind | ||
Parameter Sets: (All) | ||
Aliases: Term | ||
|
||
Required: True | ||
Position: 0 | ||
Default value: None | ||
Accept pipeline input: True (ByValue) | ||
Accept wildcard characters: False | ||
``` | ||
### -TargetTermSet | ||
The identifier of the term set where the term needs to be moved, either in the form of its name or its GUID | ||
```yaml | ||
Type: TaxonomyTermSetPipeBind | ||
Parameter Sets: By Term Id, By Term Name | ||
Aliases: | ||
|
||
Required: True | ||
Position: 0 | ||
Default value: None | ||
Accept pipeline input: True (ByValue) | ||
Accept wildcard characters: False | ||
``` | ||
### -TargetTermGroup | ||
The identifier of the term group where the term needs to be moved, either in the form of its name or its GUID | ||
```yaml | ||
Type: TaxonomyTermGroupPipeBind | ||
Parameter Sets: By Term Id, By Term Name | ||
Aliases: | ||
|
||
Required: True | ||
Position: 0 | ||
Default value: None | ||
Accept pipeline input: True (ByValue) | ||
Accept wildcard characters: False | ||
``` | ||
### -TermSet | ||
The identifier of the term set where the term is present, in the form of its name | ||
```yaml | ||
Type: TaxonomyTermSetPipeBind | ||
Parameter Sets: By Term Name | ||
Aliases: | ||
|
||
Required: True | ||
Position: 0 | ||
Default value: None | ||
Accept pipeline input: True (ByValue) | ||
Accept wildcard characters: False | ||
``` | ||
### -TermGroup | ||
The identifier of the term set where the term group is present, in the form of its name | ||
```yaml | ||
Type: TaxonomyTermGroupPipeBind | ||
Parameter Sets: By Term Name | ||
Aliases: | ||
|
||
Required: True | ||
Position: 0 | ||
Default value: None | ||
Accept pipeline input: True (ByValue) | ||
Accept wildcard characters: False | ||
``` | ||
### -TargetTerm | ||
The identifier of the term where the term needs to be moved, in the form of its GUID | ||
```yaml | ||
Type: TaxonomyTermPipeBind | ||
Parameter Sets: Move To Term | ||
Aliases: | ||
|
||
Required: True | ||
Position: 0 | ||
Default value: None | ||
Accept pipeline input: True (ByValue) | ||
Accept wildcard characters: False | ||
``` | ||
### -MoveToTerm | ||
To be provided if the term needs to be moved to another term | ||
```yaml | ||
Type: SwitchParameter | ||
Parameter Sets: Move To Term | ||
|
||
Required: True | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
### -TermStore | ||
Term store to use; if not specified the default term store is used. | ||
```yaml | ||
Type: TaxonomyTermStorePipeBind | ||
Parameter Sets: (All) | ||
Aliases: | ||
|
||
Required: False | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
--- | ||
Module Name: PnP.PowerShell | ||
title: Move-PnPTermSet | ||
schema: 2.0.0 | ||
applicable: SharePoint Online | ||
external help file: PnP.PowerShell.dll-Help.xml | ||
online version: https://pnp.github.io/powershell/cmdlets/Move-PnPTermSet.html | ||
--- | ||
|
||
# Move-PnPTermSet | ||
|
||
## SYNOPSIS | ||
|
||
Moves taxonomy term set from one term group to another | ||
|
||
## SYNTAX | ||
|
||
### By Term Id | ||
``` | ||
Move-PnPTermSet -Identity <Guid> -TermGroup <Guid> -TargetTermGroup <Guid> [-TermStore <TaxonomyTermStorePipeBind>] | ||
``` | ||
|
||
### By Term Name | ||
``` | ||
Move-PnPTermSet -Identity <String> -TermGroup <String> -TargetTermGroup <String> [-TermStore <TaxonomyTermStorePipeBind>] | ||
``` | ||
|
||
## DESCRIPTION | ||
This cmdlet moves taxonomy term set from one term group to another. | ||
|
||
## EXAMPLES | ||
|
||
### Example 1 | ||
```powershell | ||
Move-PnPTermSet -Identity 81e0a4b8-701d-459c-ad61-a1c7a81810ff -TermGroup 17e16b98-a8c2-4db6-a860-5c42dbc818f4 -TargetTermGroup cf33d1cd-42d8-431c-9e43-3d8dab9ea8fd | ||
``` | ||
|
||
Moves term set by id. | ||
|
||
### Example 2 | ||
```powershell | ||
Move-PnPTermSet -Identity "OperationLevel-1 Test" -TermGroup "FromPowerAutomate" -TargetTermGroup "TargetTermGroup" | ||
``` | ||
|
||
Moves term set by name. | ||
|
||
## PARAMETERS | ||
|
||
### -Identity | ||
The identifier of the term set that needs to be moved, either in the form of its name or its GUID | ||
|
||
```yaml | ||
Type: TaxonomyTermSetPipeBind | ||
Parameter Sets: (All) | ||
Aliases: TermSet | ||
|
||
Required: True | ||
Position: 0 | ||
Default value: None | ||
Accept pipeline input: True (ByValue) | ||
Accept wildcard characters: False | ||
``` | ||
### -TermGroup | ||
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. | ||
```yaml | ||
Type: TaxonomyTermGroupPipeBind | ||
Parameter Sets: (All) | ||
Aliases: | ||
|
||
Required: True | ||
Position: 0 | ||
Default value: None | ||
Accept pipeline input: True (ByValue) | ||
Accept wildcard characters: False | ||
``` | ||
### -TargetTermGroup | ||
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. | ||
```yaml | ||
Type: TaxonomyTermGroupPipeBind | ||
Parameter Sets: (All) | ||
Aliases: | ||
|
||
Required: True | ||
Position: 0 | ||
Default value: None | ||
Accept pipeline input: True (ByValue) | ||
Accept wildcard characters: False | ||
``` | ||
### -TermStore | ||
Term store to use; if not specified the default term store is used. | ||
```yaml | ||
Type: TaxonomyTermStorePipeBind | ||
Parameter Sets: (All) | ||
Aliases: | ||
|
||
Required: False | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
using Microsoft.SharePoint.Client; | ||
using Microsoft.SharePoint.Client.Taxonomy; | ||
using PnP.PowerShell.Commands.Base.PipeBinds; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Management.Automation; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace PnP.PowerShell.Commands.Taxonomy | ||
{ | ||
[Cmdlet(VerbsCommon.Move, "PnPTerm")] | ||
public class MoveTerm : PnPSharePointCmdlet | ||
{ | ||
private const string ParameterSet_TERMID = "By Term Id"; | ||
private const string ParameterSet_TERMNAME = "By Term Name"; | ||
private const string ParameterSet_MoveToTerm = "Move To Term"; | ||
|
||
[Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = ParameterSet_MoveToTerm)] | ||
[Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = ParameterSet_TERMID)] | ||
[Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = ParameterSet_TERMNAME)] | ||
[Alias("Term")] | ||
public TaxonomyTermPipeBind Identity; | ||
|
||
[Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = ParameterSet_TERMID)] | ||
[Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = ParameterSet_TERMNAME)] | ||
public TaxonomyTermSetPipeBind TargetTermSet; | ||
|
||
[Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = ParameterSet_TERMID)] | ||
[Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = ParameterSet_TERMNAME)] | ||
public TaxonomyTermGroupPipeBind TargetTermGroup; | ||
|
||
[Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = ParameterSet_TERMNAME)] | ||
public TaxonomyTermSetPipeBind TermSet; | ||
|
||
[Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = ParameterSet_TERMNAME)] | ||
public TaxonomyTermGroupPipeBind TermGroup; | ||
|
||
[Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = ParameterSet_MoveToTerm)] | ||
public TaxonomyTermPipeBind TargetTerm; | ||
|
||
[Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = ParameterSet_MoveToTerm)] | ||
public SwitchParameter MoveToTerm; | ||
|
||
[Parameter(Mandatory = false, ParameterSetName = ParameterAttribute.AllParameterSets)] | ||
[Alias("TermStoreName")] | ||
public TaxonomyTermStorePipeBind TermStore; | ||
|
||
protected override void ExecuteCmdlet() | ||
{ | ||
var taxonomySession = TaxonomySession.GetTaxonomySession(ClientContext); | ||
// Get Term Store | ||
TermStore termStore = null; | ||
if (TermStore == null) | ||
{ | ||
termStore = taxonomySession.GetDefaultSiteCollectionTermStore(); | ||
} | ||
else | ||
{ | ||
termStore = TermStore.GetTermStore(taxonomySession); | ||
} | ||
if (MoveToTerm.ToBool()) | ||
{ | ||
Term sourceterm = Identity.GetTerm(ClientContext, termStore, null, false, null); | ||
Term destinationterm = TargetTerm.GetTerm(ClientContext, termStore, null, false, null); | ||
|
||
sourceterm.Move(destinationterm); | ||
ClientContext.ExecuteQueryRetry(); | ||
} | ||
else | ||
{ | ||
Term term = null; | ||
TermSet destinationtermSet = null; | ||
if (ParameterSetName == ParameterSet_TERMID) | ||
{ | ||
term = Identity.GetTerm(ClientContext, termStore, null, false, null); | ||
TermGroup destinationtermGroup = TargetTermGroup.GetGroup(termStore); | ||
destinationtermSet = TargetTermSet.GetTermSet(destinationtermGroup); | ||
} | ||
else | ||
{ | ||
TermGroup termGroup = TermGroup.GetGroup(termStore); | ||
TermSet termSet = TermSet.GetTermSet(termGroup); | ||
term = Identity.GetTerm(ClientContext, termStore, termSet, false, null); | ||
TermGroup destinationtermGroup = TargetTermGroup.GetGroup(termStore); | ||
destinationtermSet = TargetTermSet.GetTermSet(destinationtermGroup); | ||
} | ||
|
||
term.Move(destinationtermSet); | ||
ClientContext.ExecuteQueryRetry(); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.