diff --git a/CHANGELOG.md b/CHANGELOG.md index bab2d0cb7..b5932c10a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Added capability to Debug the module in Visual Studio. [#1880](https://github.com/pnp/powershell/pull/1880) - Added `Set-PnPTeamsChannelUser` cmdlet to update the role of user in a private channel. [#1865](https://github.com/pnp/powershell/pull/1865) - Added `Restart-PnPFlowRun` which allows for a failed Power Automate flow run to be retried [#1915](https://github.com/pnp/powershell/pull/1915) +- Added `-IncludeDeprecated` parameter to `Get-PnPTerm` cmdlet to fetch deprecated terms if specified [#1903](https://github.com/pnp/powershell/pull/1903) ### Changed - Changed `Sync-PnPSharePointUserProfilesFromAzureActiveDirectory` to map users based on their Ids instead which should resolve some issues around user identities reporting not to exist. You can use the new `-IdType` option to switch it back to `PrincipalName` if needed. [#1752](https://github.com/pnp/powershell/pull/1752) diff --git a/documentation/Get-PnPTerm.md b/documentation/Get-PnPTerm.md index 789cb50ae..0c7175935 100644 --- a/documentation/Get-PnPTerm.md +++ b/documentation/Get-PnPTerm.md @@ -30,7 +30,7 @@ Get-PnPTerm -TermGroup [-TermStore ] [-Recursive] - [-IncludeChildTerms] [-Connection ] [-Includes ] [] + [-IncludeChildTerms][-IncludeDeprecated] [-Connection ] [-Includes ] [] ``` ## DESCRIPTION @@ -74,6 +74,13 @@ $term.Labels Returns all the localized labels for the term named "Small Finance", from the "Departments" termset in a term group called "Corporate" +### EXAMPLE 6 +```powershell +Get-PnPTerm -Identity "Small Finance" -TermSet "Departments" -TermGroup "Corporate" -Recursive -IncludeDeprecated +``` + +Returns the deprecated term named "Small Finance", from the "Departments" termset in a term group called "Corporate" from the site collection termstore even if it is a subterm below "Finance" + ## PARAMETERS ### -Connection @@ -174,6 +181,20 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -IncludeDeprecated +Includes the deprecated terms if available. + +```yaml +Type: SwitchParameter +Parameter Sets: By Term name + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ## RELATED LINKS [Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp) diff --git a/src/Commands/Base/PipeBinds/TaxonomyTermPipeBind.cs b/src/Commands/Base/PipeBinds/TaxonomyTermPipeBind.cs index e8df26fa9..be2956e1f 100644 --- a/src/Commands/Base/PipeBinds/TaxonomyTermPipeBind.cs +++ b/src/Commands/Base/PipeBinds/TaxonomyTermPipeBind.cs @@ -39,7 +39,7 @@ public TaxonomyTermPipeBind(Term item) public Term Item => _item; - public Term GetTerm(ClientContext clientContext, TermStore termStore, TermSet termSet, bool recursive, Expression>[] expressions = null) + public Term GetTerm(ClientContext clientContext, TermStore termStore, TermSet termSet, bool recursive, Expression>[] expressions = null, bool includeDeprecated = false) { Term term = null; if (_id != Guid.Empty) @@ -55,20 +55,35 @@ public Term GetTerm(ClientContext clientContext, TermStore termStore, TermSet te } else { - var lmi = new LabelMatchInformation(clientContext) + if (includeDeprecated) { - TrimUnavailable = true, - TermLabel = termName - }; + var allTerms = termSet.GetAllTermsIncludeDeprecated(); + clientContext.Load(allTerms); + clientContext.ExecuteQueryRetry(); - var termMatches = termSet.GetTerms(lmi); - clientContext.Load(termMatches); - clientContext.ExecuteQueryRetry(); - - if (termMatches.AreItemsAvailable) + if (allTerms.AreItemsAvailable) + { + term = allTerms.Where(t => t.Name == termName).FirstOrDefault(); + } + } + else { - term = termMatches.FirstOrDefault(); + var lmi = new LabelMatchInformation(clientContext) + { + TrimUnavailable = true, + TermLabel = termName + }; + + var termMatches = termSet.GetTerms(lmi); + clientContext.Load(termMatches); + clientContext.ExecuteQueryRetry(); + + if (termMatches.AreItemsAvailable) + { + term = termMatches.FirstOrDefault(); + } } + } } else diff --git a/src/Commands/Taxonomy/GetTerm.cs b/src/Commands/Taxonomy/GetTerm.cs index 51fdfdd04..8d5c0aa36 100644 --- a/src/Commands/Taxonomy/GetTerm.cs +++ b/src/Commands/Taxonomy/GetTerm.cs @@ -37,6 +37,9 @@ public class GetTerm : PnPRetrievalsCmdlet [Parameter(Mandatory = false, ParameterSetName = ParameterSet_TERMNAME)] public TaxonomyTermPipeBind ParentTerm; + [Parameter(Mandatory = false, ParameterSetName = ParameterSet_TERMNAME)] + public SwitchParameter IncludeDeprecated; + protected override void ExecuteCmdlet() { DefaultRetrievalExpressions = new Expression>[] { g => g.Name, g => g.TermsCount, g => g.Id }; @@ -77,7 +80,7 @@ protected override void ExecuteCmdlet() if (Identity != null && ParentTerm == null) { - var term = Identity.GetTerm(ClientContext, termStore, termSet, Recursive, RetrievalExpressions); + var term = Identity.GetTerm(ClientContext, termStore, termSet, Recursive, RetrievalExpressions, IncludeDeprecated); if (IncludeChildTerms.IsPresent && term.TermsCount > 0) { @@ -87,7 +90,7 @@ protected override void ExecuteCmdlet() } else if (Identity != null && ParentTerm != null) { - var term = ParentTerm.GetTerm(ClientContext, termStore, termSet, Recursive, RetrievalExpressions); + var term = ParentTerm.GetTerm(ClientContext, termStore, termSet, Recursive, RetrievalExpressions, IncludeDeprecated); if (IncludeChildTerms.IsPresent && term.TermsCount > 0) {