【问题标题】:Get SharePoint online Term set and create term if does not exist in PowerShell获取 SharePoint Online 术语集并在 PowerShell 中不存在时创建术语
【发布时间】:2020-09-23 15:23:14
【问题描述】:

我在 SharePoint 在线管理中的术语库层次结构:

组织 组织单位 部门 测试设施管理 地点 测试地点

我只想在“部门”中搜索“测试设施管理”,如果不存在,则在“部门”下创建。

我有下面的 PowerShell 脚本来检查并在 SharePoint Online 中创建一个术语。但我想在“部门”中检查该术语。我没有任何成功。非常感谢任何帮助。

$TermGroupName = "Organisation"
$TermSetName = "Org Units"
$TermName="Test Facilities Management"
If(-Not(Get-PnPTerm -Identity $TermName -TermSet $TermSetName -TermGroup $TermGroupName -Recursive -ErrorAction SilentlyContinue))
{
    #Create new Term
    New-PnPTerm -Name $TermName -TermSet $TermSetName -TermGroup $TermGroupName 
}

【问题讨论】:

    标签: powershell sharepoint-online


    【解决方案1】:

    您似乎想创建一个子项。
    我的测试代码供大家参考:

    $TermGroupName = "testMetaData"#Group
    $TermSetName = "test"#term group
    $TermName="test1"#term set
    $subTermName="subTerm"#subterm
    $username = "amos@contoso.onmicrosoft.com"
    $password = "Password"
    $cred = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $userName, $(convertto-securestring $Password -asplaintext -force)
    Connect-PnPOnline -Url https://contoso.sharepoint.com/sites/dev -Credentials $cred
    $ctx = Get-PnPContext
    $term=Get-PnPTerm -Identity $TermName -TermSet $TermSetName -TermGroup $TermGroupName -Recursive -ErrorAction SilentlyContinue    
    $subterm=Get-PnPTerm -Identity $subTermName -TermSet $TermSetName -TermGroup $TermGroupName -Recursive -ErrorAction SilentlyContinue
    if($subterm.Name -eq $null){
      $guid=New-Guid
      $term.CreateTerm($subTermName, 1033, $guid)
      $ctx.Load($term)
    $ctx.ExecuteQuery()
    }
    

    【讨论】:

    • 这解决了部分问题,即在一个术语下创建一个 subTermName。有没有办法在一个词中搜索一个子词?就像只在“部门”一词中找到“测试设施管理”。递归标志将在所有 TermSetName 中搜索一个术语。
    • 没有oob api获取sunterm。我们可能需要先获取父term,然后循环遍历父term的terms属性。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-09-01
    • 1970-01-01
    • 2017-05-31
    • 2018-04-26
    • 2022-07-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多