From 7e013a324090af9f1253f9ad30e50a6a23af9c8f Mon Sep 17 00:00:00 2001 From: Markus Hanisch Date: Mon, 27 Jan 2020 22:48:15 +0100 Subject: [PATCH 1/4] Added example to add default term label for other LCID This is an example on how to create multilingual default term labels for a different LCID whilst creating a new taxonomy terms. Also see PR: https://github.com/MicrosoftDocs/office-docs-powershell/pull/4763/ --- Commands/Taxonomy/NewTerm.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Commands/Taxonomy/NewTerm.cs b/Commands/Taxonomy/NewTerm.cs index be31ea8de..7eed44e3d 100644 --- a/Commands/Taxonomy/NewTerm.cs +++ b/Commands/Taxonomy/NewTerm.cs @@ -20,6 +20,14 @@ namespace SharePointPnP.PowerShell.Commands.Taxonomy (Code = @"PS:> New-PnPTerm -TermSet ""Departments"" -TermGroup ""Corporate"" -Name ""Finance""", Remarks = @"Creates a new taxonomy term named ""Finance"" in the termset Departments which is located in the ""Corporate"" termgroup", SortOrder = 1)] + [CmdletExample( + Code = @"PS:> $context = Get-PnPContext +PS:> $term = New-PnPTerm -Name ""Finance"" -TermSet ""Departments"" -TermGroup ""Corporate"" -LCID 1033 +PS:> $createLabel = $term.CreateLabel(""Finanzwesen"", 1031, $true) +PS:> $context.Load($term) +PS:> Invoke-PnPQuery", + Remarks = @"This example creates a new English taxonomy term named ""Finance"" in the termset Departments which is located in the ""Corporate"" termgroup and adds a German default label for the newly created English term by means of the CreateLabel method", + SortOrder = 2)] public class NewTerm : PnPCmdlet { [Parameter(Mandatory = true, ValueFromPipeline = true, HelpMessage = "The name of the term.")] From f2110e03f897d22372a6880dcb90c8ee22868179 Mon Sep 17 00:00:00 2001 From: Koen Zomers Date: Tue, 28 Jan 2020 10:42:19 +0100 Subject: [PATCH 2/4] Resubmit of PR2474 --- CHANGELOG.md | 1 + Commands/Taxonomy/NewTerm.cs | 12 ++++-------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bd193abdb..d4091fd9d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Gautam Sheth [gautamdsheth] - Craig Hair [MacsInSpace] - Dan Cecil [danielcecil] +- Markus Hanisch [Markus-Hanisch] ## [3.17.2001.2] diff --git a/Commands/Taxonomy/NewTerm.cs b/Commands/Taxonomy/NewTerm.cs index 7eed44e3d..77907e495 100644 --- a/Commands/Taxonomy/NewTerm.cs +++ b/Commands/Taxonomy/NewTerm.cs @@ -1,9 +1,7 @@ using System; using System.Collections; -using System.Collections.Generic; using System.Globalization; using System.Management.Automation; -using System.Runtime.InteropServices; using Microsoft.SharePoint.Client; using Microsoft.SharePoint.Client.Taxonomy; using SharePointPnP.PowerShell.CmdletHelpAttributes; @@ -15,7 +13,8 @@ namespace SharePointPnP.PowerShell.Commands.Taxonomy [CmdletHelp(@"Creates a taxonomy term", Category = CmdletHelpCategory.Taxonomy, OutputType = typeof(Term), - OutputTypeLink = "https://msdn.microsoft.com/en-us/library/microsoft.sharepoint.client.taxonomy.term.aspx")] + OutputTypeLink = "https://docs.microsoft.com/en-us/previous-versions/office/sharepoint-csom/jj166573(v=office.15)", + SupportedPlatform = CmdletSupportedPlatform.All)] [CmdletExample (Code = @"PS:> New-PnPTerm -TermSet ""Departments"" -TermGroup ""Corporate"" -Name ""Finance""", Remarks = @"Creates a new taxonomy term named ""Finance"" in the termset Departments which is located in the ""Corporate"" termgroup", @@ -23,10 +22,9 @@ namespace SharePointPnP.PowerShell.Commands.Taxonomy [CmdletExample( Code = @"PS:> $context = Get-PnPContext PS:> $term = New-PnPTerm -Name ""Finance"" -TermSet ""Departments"" -TermGroup ""Corporate"" -LCID 1033 -PS:> $createLabel = $term.CreateLabel(""Finanzwesen"", 1031, $true) -PS:> $context.Load($term) +PS:> $term.CreateLabel(""Finanzwesen"", 1031, $true) PS:> Invoke-PnPQuery", - Remarks = @"This example creates a new English taxonomy term named ""Finance"" in the termset Departments which is located in the ""Corporate"" termgroup and adds a German default label for the newly created English term by means of the CreateLabel method", + Remarks = @"This example creates a new English taxonomy term named ""Finance"" in the termset ""Departments"" which is located in the ""Corporate"" termgroup and adds a German default label for the newly created English term by means of the CreateLabel method", SortOrder = 2)] public class NewTerm : PnPCmdlet { @@ -46,7 +44,6 @@ public class NewTerm : PnPCmdlet HelpMessage = "The termgroup to create the term in.")] public TermGroupPipeBind TermGroup; - [Parameter(Mandatory = false, HelpMessage = "Descriptive text to help users understand the intended use of this term.")] public string Description; @@ -137,6 +134,5 @@ protected override void ExecuteCmdlet() ClientContext.ExecuteQueryRetry(); WriteObject(term); } - } } From 35a9f9cd322cbb3e893294bc5e9e56854aa7357c Mon Sep 17 00:00:00 2001 From: Koen Zomers Date: Tue, 28 Jan 2020 12:22:10 +0100 Subject: [PATCH 3/4] Additional code cleanup --- Commands/Taxonomy/NewTerm.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Commands/Taxonomy/NewTerm.cs b/Commands/Taxonomy/NewTerm.cs index 77907e495..2b2d08ae4 100644 --- a/Commands/Taxonomy/NewTerm.cs +++ b/Commands/Taxonomy/NewTerm.cs @@ -40,8 +40,7 @@ public class NewTerm : PnPCmdlet [Parameter(Mandatory = true, ValueFromPipeline = true, Position = 0, HelpMessage = "The termset to add the term to.")] public TaxonomyItemPipeBind TermSet; - [Parameter(Mandatory = true, ValueFromPipeline = true, - HelpMessage = "The termgroup to create the term in.")] + [Parameter(Mandatory = true, ValueFromPipeline = true, HelpMessage = "The termgroup to create the term in.")] public TermGroupPipeBind TermGroup; [Parameter(Mandatory = false, HelpMessage = "Descriptive text to help users understand the intended use of this term.")] @@ -53,8 +52,7 @@ public class NewTerm : PnPCmdlet [Parameter(Mandatory = false, HelpMessage = "Custom Properties")] public Hashtable LocalCustomProperties; - [Parameter(Mandatory = false, ParameterSetName = ParameterAttribute.AllParameterSets, - HelpMessage = "Term store to check; if not specified the default term store is used.")] + [Parameter(Mandatory = false, ParameterSetName = ParameterAttribute.AllParameterSets, HelpMessage = "Term store to check; if not specified the default term store is used.")] [Alias("TermStoreName")] public GenericObjectNameIdPipeBind TermStore; From 908a0e88da1b54b53c2a356cf323a1ad2e55cc26 Mon Sep 17 00:00:00 2001 From: Koen Zomers Date: Tue, 28 Jan 2020 13:23:51 +0100 Subject: [PATCH 4/4] Added New-PnPTermLabel to solve this properly --- CHANGELOG.md | 1 + .../SharePointPnP.PowerShell.Commands.csproj | 1 + Commands/Taxonomy/GetTerm.cs | 7 ++- Commands/Taxonomy/NewTerm.cs | 7 --- Commands/Taxonomy/NewTermLabel.cs | 51 +++++++++++++++++++ 5 files changed, 59 insertions(+), 8 deletions(-) create mode 100644 Commands/Taxonomy/NewTermLabel.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index d4091fd9d..74169bf84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Added ability to use `Set-PnPRequestAccessEmails` with `-Disabled` to disable requesting access to a site and `-Disabled:$false` to set the access requests to be sent to the default owners of the site [PR #2456](https://github.com/SharePoint/PnP-PowerShell/pull/2456) - Added `Get-PnPSiteScriptFromList` and `Get-PnPSiteScriptFromWeb` commands which allow generation of Site Script JSON based off of existing lists or an entire site [PR # 2459](https://github.com/SharePoint/PnP-PowerShell/pull/2459) - Added `-Aggregations` argument to `Add-PnPView` and `Set-PnPView` to allow for creating a Totals count in a view [PR #2257](https://github.com/SharePoint/PnP-PowerShell/pull/2257) +- Added `New-PnPTermLabel` to add a localized label to an existing taxonomy term [PR #2475](https://github.com/SharePoint/PnP-PowerShell/pull/2475) ### Changed - Optimized Invoke-PnPSearchQuery when using the -All parameter to ensure all results are returned by ordering on IndexDocId, and changed the default ClientType to 'PnP' diff --git a/Commands/SharePointPnP.PowerShell.Commands.csproj b/Commands/SharePointPnP.PowerShell.Commands.csproj index 7600a3f13..ca14e7c2b 100644 --- a/Commands/SharePointPnP.PowerShell.Commands.csproj +++ b/Commands/SharePointPnP.PowerShell.Commands.csproj @@ -851,6 +851,7 @@ + diff --git a/Commands/Taxonomy/GetTerm.cs b/Commands/Taxonomy/GetTerm.cs index fb84ba18d..0ee3cd6fb 100644 --- a/Commands/Taxonomy/GetTerm.cs +++ b/Commands/Taxonomy/GetTerm.cs @@ -29,7 +29,12 @@ namespace SharePointPnP.PowerShell.Commands.Taxonomy [CmdletExample( Code = @"PS:> Get-PnPTerm -Identity ""Small Finance"" -TermSet ""Departments"" -TermGroup ""Corporate"" -Recursive", Remarks = @"Returns the term named ""Small Finance"", from the ""Departments"" termset in a term group called ""Corporate"" from the site collection termstore even if it's a subterm below ""Finance""", - SortOrder = 2)] + SortOrder = 3)] + [CmdletExample( + Code = @"PS:> $term = Get-PnPTerm -Identity ""Small Finance"" -TermSet ""Departments"" -TermGroup ""Corporate"" -Include Labels +PS:> $term.Labels", + Remarks = @"Returns all the localized labels for the term named ""Small Finance"", from the ""Departments"" termset in a term group called ""Corporate""", + SortOrder = 4)] public class GetTerm : PnPRetrievalsCmdlet { private const string ParameterSet_TERM = "By Term Id"; diff --git a/Commands/Taxonomy/NewTerm.cs b/Commands/Taxonomy/NewTerm.cs index 2b2d08ae4..cca573873 100644 --- a/Commands/Taxonomy/NewTerm.cs +++ b/Commands/Taxonomy/NewTerm.cs @@ -19,13 +19,6 @@ namespace SharePointPnP.PowerShell.Commands.Taxonomy (Code = @"PS:> New-PnPTerm -TermSet ""Departments"" -TermGroup ""Corporate"" -Name ""Finance""", Remarks = @"Creates a new taxonomy term named ""Finance"" in the termset Departments which is located in the ""Corporate"" termgroup", SortOrder = 1)] - [CmdletExample( - Code = @"PS:> $context = Get-PnPContext -PS:> $term = New-PnPTerm -Name ""Finance"" -TermSet ""Departments"" -TermGroup ""Corporate"" -LCID 1033 -PS:> $term.CreateLabel(""Finanzwesen"", 1031, $true) -PS:> Invoke-PnPQuery", - Remarks = @"This example creates a new English taxonomy term named ""Finance"" in the termset ""Departments"" which is located in the ""Corporate"" termgroup and adds a German default label for the newly created English term by means of the CreateLabel method", - SortOrder = 2)] public class NewTerm : PnPCmdlet { [Parameter(Mandatory = true, ValueFromPipeline = true, HelpMessage = "The name of the term.")] diff --git a/Commands/Taxonomy/NewTermLabel.cs b/Commands/Taxonomy/NewTermLabel.cs new file mode 100644 index 000000000..7a5a22c62 --- /dev/null +++ b/Commands/Taxonomy/NewTermLabel.cs @@ -0,0 +1,51 @@ +using System; +using System.Management.Automation; +using Microsoft.SharePoint.Client; +using Microsoft.SharePoint.Client.Taxonomy; +using SharePointPnP.PowerShell.CmdletHelpAttributes; +using SharePointPnP.PowerShell.Commands.Base.PipeBinds; + +namespace SharePointPnP.PowerShell.Commands.Taxonomy +{ + [Cmdlet(VerbsCommon.New, "PnPTermLabel", SupportsShouldProcess = false)] + [CmdletHelp(@"Creates a localized label for a taxonomy term", + Category = CmdletHelpCategory.Taxonomy, + OutputType = typeof(Label), + OutputTypeLink = "https://docs.microsoft.com/en-us/dotnet/api/microsoft.sharepoint.taxonomy.label", + DetailedDescription = "Creates a localized label for a taxonomy term. Use Get-PnPTerm -Include Labels to request the current labels on a taxonomy term.", + SupportedPlatform = CmdletSupportedPlatform.All)] + [CmdletExample + (Code = @"PS:> New-PnPTermLabel -Name ""Finanzwesen"" -Lcid 1031 -Term (Get-PnPTerm -Identity ""Finance"" -TermSet ""Departments"" -TermGroup ""Corporate"")", + Remarks = @"Creates a new localized taxonomy label in German (LCID 1031) named ""Finanzwesen"" for the term ""Finance"" in the termset Departments which is located in the ""Corporate"" termgroup", + SortOrder = 1)] + [CmdletExample + (Code = @"PS:> Get-PnPTerm -Identity ""Finance"" -TermSet ""Departments"" -TermGroup ""Corporate"" | New-PnPTermLabel -Name ""Finanzwesen"" -Lcid 1031", + Remarks = @"Creates a new localized taxonomy label in German (LCID 1031) named ""Finanzwesen"" for the term ""Finance"" in the termset Departments which is located in the ""Corporate"" termgroup", + SortOrder = 2)] + public class NewTermLabel : PnPCmdlet + { + [Parameter(Mandatory = true, ValueFromPipeline = true, Position = 0, HelpMessage = "The term to add the localized label to")] + public TaxonomyItemPipeBind Term; + + [Parameter(Mandatory = true, HelpMessage = "The localized name of the term")] + public string Name; + + [Parameter(Mandatory = true, HelpMessage = "The locale id to use for the localized term")] + public int Lcid; + + [Parameter(Mandatory = false, HelpMessage = "Makes this new label the default label", ParameterSetName = ParameterAttribute.AllParameterSets)] + public SwitchParameter IsDefault = true; + + protected override void ExecuteCmdlet() + { + if (Term.Item == null) + { + throw new ArgumentException("You must pass in a Term instance to this command", nameof(Term)); + } + + var label = Term.Item.CreateLabel(Name, Lcid, IsDefault.IsPresent ? IsDefault.ToBool() : true); + ClientContext.ExecuteQueryRetry(); + WriteObject(label); + } + } +}