当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] SharePoint Online:使用 PowerShell 在术语库中创建新组

作者:精品下载站 日期:2024-12-14 14:17:48 浏览:14 分类:玩电脑

SharePoint Online:使用 PowerShell 在术语库中创建新组


要求:在 SharePoint Online 术语库中创建一个新组。

如何在 SharePoint Online 中创建新术语组?

您是否曾经需要在 SharePoint Online 术语库中创建新组?在本文中,我们将逐步介绍使用 SharePoint 管理中心在术语库中创建新组所需的步骤。我们还将提供一些脚本脚本,您可以将其用作在 SharePoint Online 中创建术语组的起点。

要在 SharePoint Online 术语库中创建新组,请执行以下步骤:

  1. 导航到您的 SharePoint 管理中心网站。 (例如,https://yourdomain-admin.sharepoint.com)
  2. 展开“内容服务”,然后单击左侧导航菜单上的“术语存储”链接。
  3. 单击“分类”标题中的三个垂直小点 >> 从菜单选项中单击“新术语组”。

    [玩转系统] SharePoint Online:使用 PowerShell 在术语库中创建新组

  4. 输入术语组的名称。按 Enter 键完成术语组的创建。

    [玩转系统] SharePoint Online:使用 PowerShell 在术语库中创建新组

创建新组后,您可以向其中添加术语集。

PowerShell 在 SharePoint Online 中添加新术语组:

如果您像大多数管理员一样,您将希望自动执行在术语库中创建新组的过程。让我向您展示如何使用 PowerShell 做到这一点。


#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.Taxonomy.dll"
  
#Variables for Processing
$AdminURL = "https://crescent-admin.sharepoint.com/"
$TermGroup ="Regions"

Try {
    #Get Credentials to connect
    $Cred = Get-Credential
    $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($AdminURL)
    $Ctx.Credentials = $Credentials

    #Get the term store
    $TaxonomySession=[Microsoft.SharePoint.Client.Taxonomy.TaxonomySession]::GetTaxonomySession($Ctx) 
    $TermStore =$TaxonomySession.GetDefaultSiteCollectionTermStore()
    $Ctx.Load($TaxonomySession)
    $Ctx.Load($TermStore)
    $Ctx.ExecuteQuery()
    
    #Check if the given group exists already
    $TermGroups = $TermStore.Groups
    $Ctx.Load($TermGroups)
    $Ctx.ExecuteQuery()
    $Group = $TermGroups | Where-Object {$_.Name -eq $TermGroup}
    
    If(-not $Group)
    {
        #Create Term Group
        $NewGroup = $TermStore.CreateGroup($TermGroup, [System.Guid]::NewGuid().toString())
        $Ctx.Load($NewGroup)
        $Ctx.ExecuteQuery()
    
        Write-host "Term Group '$TermGroup' Created Successfully!" -ForegroundColor Green
    }
    else
    {
        Write-host "Term Group '$TermGroup' Exists Already!" -ForegroundColor Yellow
    }
}
Catch {
    write-host -f Red "Error Adding Term Group!" $_.Exception.Message
}

使用 PnP PowerShell 在 SharePoint Online 中创建术语组

在 SharePoint Online 中,术语存储提供了一种跨多个网站和网站集管理分类和元数据的方法。在术语库中创建新组可以帮助组织和管理术语集和术语。让我们看看如何使用 PnP PowerShell 在术语库中创建新组:


#Config Variables
$AdminCenterURL = "https://Crescent-admin.sharepoint.com"
$TermGroupName = "Regions"
$TermGroupDescription ="Term Group for Deals Pipeline Regions"

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive

#Check if Term group exists
If(-Not(Get-PnPTermGroup -Identity $TermGroupName -ErrorAction SilentlyContinue))
{
    #Create new group in Termstore
    New-PnPTermGroup -Name $TermGroupName -Description $TermGroupDescription
    Write-host -f Green "Term Group '$TermGroupName' created successfully!"
}
Else
{
    Write-host -f Yellow "Term Group '$TermGroupName' already exists!"
}

总之,术语库可以成为管理 SharePoint Online 租户的分类和元数据的有用工具。在 SharePoint Online 的术语库中创建新组是一个简单的过程,只需几个简单的步骤即可完成。按照本文概述的步骤,您可以轻松在术语库中创建新组并开始组织术语集和术语。

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯