转载请注明出自天外归云的博客园: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。如果有同名情况出现会提示相应内容已存在,不会重复创建: