获取 SharePoint 在线术语集并创建术语(如果 PowerShell 中不存在)
Get SharePoint online Term set and create term if does not exist in PowerShell
我在 SharePoint 在线管理中的术语库层次结构:
Organisation
Org Units
Department
Test Facilities Management
Location
Test location
我只想在'Department'中搜索'Test Facilities Management',如果不存在则在'Department'下创建。
我有下面的 PowerShell 脚本可以在 SharePoint Online 中检查和创建术语。但我想检查 only in 'Department' 中的术语。我没有任何成功。非常感谢任何帮助。
$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
}
您似乎想创建一个子项。
我的测试代码供大家参考:
$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()
}
我在 SharePoint 在线管理中的术语库层次结构:
Organisation Org Units Department Test Facilities Management Location Test location
我只想在'Department'中搜索'Test Facilities Management',如果不存在则在'Department'下创建。
我有下面的 PowerShell 脚本可以在 SharePoint Online 中检查和创建术语。但我想检查 only in 'Department' 中的术语。我没有任何成功。非常感谢任何帮助。
$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
}
您似乎想创建一个子项。
我的测试代码供大家参考:
$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()
}