SharePoint自动化系列——创建MMS terms

转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/

PowerShell脚本实现MMS group、termSet、terms的自动化创建:

Add-PSSnapin Microsoft.SharePoint.PowerShell
function CreateTerms{
    param($siteUrl,$groupName,$termSetName,$termsCount)
    #Connect to the Metadata Service
    $taxSite = Get-SPSite $siteUrl
    $taxonomySession = Get-SPTaxonomySession -site $taxSite
    $termStore = $taxonomySession.TermStores["Managed Metadata Service"]
    $flag = $true
    foreach($group in $termStore.Groups)
    {
        if($group.name -eq $groupName)
        {
            Write-Warning "Group exists."
            $flag = $false
        }
    }
    if($flag -eq $true)
    {
        $termGroup = $termStore.CreateGroup($groupName)
        $termStore.CommitAll()
    }else
    {
        $termGroup = $termStore.Groups[$groupName]
    }
    $flag = $true
    foreach($termSet in $termGroup.termSets)
    {
        if($termSet.name -eq $termSetName)
        {
            Write-Warning "TermSet exists."
            $flag = $false
        }
    }
    if($flag -eq $true)
    {
        $termSet = $termGroup.createTermSet($termSetName)
        $termStore.CommitAll()
    }else
    {
        $termSet = $termGroup.termSets[$termSetName]
    }
    for($i=1;$i -le $termsCount;$i++)
    {
        try{
            $termSet.CreateTerm("Term"+$i,1033)
            $termStore.CommitAll()
        }catch
        {
            Write-Warning "Term exists."
        }
    }
   Read-Host } CreateTerms
-siteUrl http://xxxx -groupName xxxx -termSetName xxxx -termsCount xx

脚本保存到ps1文件,在server上右键run with PowerShell即可。

实现:在Managed Metadata Service这个service application下创建指定名字的Group,Termset以及指定数量的Terms。如果有同名情况出现会提示相应内容已存在,不会重复创建:

转载于:https://www.cnblogs.com/LanTianYou/p/5029360.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值