Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created a new Cmdlet for Mergeing Terms and a documentation page. #3638

Merged
merged 4 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions documentation/Merge-PnPTerm.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
---
Module Name: PnP.PowerShell
title: Merge-PnPTerm
schema: 2.0.0
applicable: SharePoint Online
external help file: PnP.PowerShell.dll-Help.xml
online version: https://pnp.github.io/powershell/cmdlets/Merge-PnPTerm.html
---

# Merge-PnPTerm

## SYNOPSIS

Merges a taxonomy term into another term.

## SYNTAX

### Merge term set into term by Term Ids

```
Merge-PnPTerm -Identity d67966b0-3b60-4331-8dc4-0b5a2ca730fc -TargetTerm 95e13729-3ccf-4ec8-998c-78e9ef1daa0b
```

## DESCRIPTION

This cmdlet merges a taxonomy term into another term.


## EXAMPLES

### Example 1
```powershell
Merge-PnPTerm -Identity d67966b0-3b60-4331-8dc4-0b5a2ca730fc -TargetTerm 95e13729-3ccf-4ec8-998c-78e9ef1daa0b
```

## PARAMETERS

### -Identity
The identifier of the term that will be merged away, in the form of 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
```

### -TargetTerm
The identifier of the term where the term will be merged into, 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
```

### -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
```
54 changes: 54 additions & 0 deletions src/Commands/Taxonomy/MergeTerm.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
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(VerbsData.Merge, "PnPTerm")]
public class MergeTerm : PnPSharePointCmdlet
{
private const string ParameterSet_TERMID = "By Term Id";

[Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = ParameterSet_TERMID)]
[Alias("Term")]
public TaxonomyTermPipeBind Identity;

[Parameter(Mandatory = true, ValueFromPipeline = true, ParameterSetName = ParameterSet_TERMID)]
public TaxonomyTermPipeBind TargetTerm;

[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);
}


Term sourceterm = Identity.GetTerm(ClientContext, termStore, null, false, null);
Term destinationterm = TargetTerm.GetTerm(ClientContext, termStore, null, false, null);

sourceterm.Merge(destinationterm);
ClientContext.ExecuteQueryRetry();


}
}
}

Loading