SharePoint Online: cree términos secundarios en el almacén de términos usando PowerShell
Requisito: Crear un término secundario en el almacén de términos de SharePoint Online
¿Cómo agregar términos secundarios en SharePoint Online?
En SharePoint Online, puede agregar términos secundarios a un término establecido en hasta 7 niveles hacia abajo, para crear una organización jerárquica de términos o dividir los términos en categorías específicas. Hay algunas formas diferentes de agregar términos secundarios a un término: con Term Store Manager o cmdlets de PowerShell. En esta publicación de blog, veremos cada opción y le mostraremos cómo agregar términos secundarios usando cada método.
El almacén de términos de SharePoint Online proporciona una interfaz sencilla para administrar los datos del almacén de términos de forma jerárquica. Podemos crear términos secundarios (o subtérminos) sobre términos existentes en el almacén de términos.
Puede crear términos secundarios sobre cualquier término existente en el almacén de términos seleccionando "Agregar término" en el menú contextual de cualquier término existente.
PowerShell para agregar términos secundarios en SharePoint Online
Esta es la forma de PowerShell para crear términos secundarios en SharePoint Online:
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Taxonomy.dll"
#Parameters
$TenantURL = "https://crescent.sharepoint.com"
$TermGroupName = "Classification"
$TermSetName = "Tags"
$ParentTermName = "Continent"
#Function to Add Child Term (or Sub-term)
Function Add-ChildTerm
{
param (
[parameter(Mandatory=$true, ValueFromPipeline=$true)][string]$TermName,
[parameter(ValueFromPipelineByPropertyName = $true)][int]$Language = 1033,
[parameter(Mandatory=$true, ValueFromPipeline=$true)][Microsoft.SharePoint.Client.Taxonomy.Term]$ParentTerm,
[parameter(Mandatory=$true, ValueFromPipeline=$true)][Microsoft.SharePoint.Client.ClientContext]$Context
)
Try {
$ChildTerm = $ParentTerm.CreateTerm($TermName, $Language, [System.Guid]::NewGuid().toString())
$ParentTerm.TermStore.CommitAll()
$Context.ExecuteQuery()
Write-host "New Term '$TermName' Added Successfully!" -ForegroundColor Green
}
Catch {
write-host -f Red "Error Adding Term:" $_.Exception.Message
}
}
Try {
#Get Credentials to connect
$Cred = Get-Credential
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($TenantURL)
$Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
#Get the term store
$TaxonomySession=[Microsoft.SharePoint.Client.Taxonomy.TaxonomySession]::GetTaxonomySession($Ctx)
$TermStore =$TaxonomySession.GetDefaultSiteCollectionTermStore()
$Ctx.Load($TaxonomySession)
$Ctx.Load($TermStore)
$Ctx.ExecuteQuery()
#Get the Term Group
$TermGroup = $TermStore.Groups.GetByName($TermGroupName)
$Ctx.Load($TermGroup)
#Get the Term Set
$TermSet = $TermGroup.TermSets.GetByName($TermSetName)
$Ctx.Load($TermSet)
#Get the Parent term
$Term = $TermSet.Terms.GetByName($ParentTermName)
$Ctx.Load($Term)
$Ctx.ExecuteQuery()
#Call the function to Create a Child Term
Add-ChildTerm -TermName "America" -ParentTerm $Term -Context $Ctx
}
Catch {
write-host -f Red "Error:" $_.Exception.Message
}
Crear términos secundarios en SharePoint Online usando PnP PowerShell
También podemos crear subtérminos usando PnP PowerShell:
#Parameters
$TenantURL = "https://crescent.sharepoint.com"
Try {
#Connect to PnP Online
Connect-PnPOnline -Url $TenantURL -Interactive
$ParentTerm = Get-PnPTerm -TermGroup "Classification" -TermSet "Tags" -Identity "Continent" -IncludeChildTerms -Recursive
$ChildTerm = $ParentTerm.CreateTerm("Asia", 1033, (New-Guid))
Invoke-PnPQuery
}
Catch {
Write-Host -f Red "Error:"$_.Exception.Message
}
