zoukankan      html  css  js  c++  java
  • 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。如果有同名情况出现会提示相应内容已存在,不会重复创建:

  • 相关阅读:
    SocketChannel 例子(转)
    多态(Polymorphism)的实现机制(上)--C++篇
    多态(Polymorphism)的实现机制(下)--Java篇
    java volatitle 多线程问题
    线程BlockingQueue (转)
    java 多态,和方法覆盖分析(转)
    MFC 调试技巧
    strlen与sizeof区别(转载)
    杭电1048
    杭电2013
  • 原文地址:https://www.cnblogs.com/LanTianYou/p/5029360.html
Copyright © 2011-2022 走看看