powershell 将所有组中的所有术语集导出为CSV文件。
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell 将所有组中的所有术语集导出为CSV文件。相关的知识,希望对你有一定的参考价值。
# ----------------------------------------------
# Author: Microsoft
# Date: 09.10.2013
# Description: Export all termsets from all groups into CSV files.
# ----------------------------------------------
$siteUrl = "<Enter URL of Central Administration>"
$outputDir = "<Enter export output path>"
function Get-TermSetsCSV() {
param($SiteUrl, $CSVOutput)
$empty = ""
$taxonomySite = Get-SPSite -Identity $SiteUrl
#Connect to Term Store in the Managed Metadata Service Application
$taxonomySession = Get-SPTaxonomySession -site $taxonomySite
$taxonomyTermStore = $taxonomySession.TermStores | Select Name
$termStore = $taxonomySession.TermStores[$taxonomyTermStore.Name]
foreach ($group in $termStore.Groups)
{
foreach($termSet in $group.TermSets)
{
$terms = @()
#The path and file name, in this case I did C:\TermSet\TermSetName.csv
$CSVFile = $CSVOutput + '\' + $termSet.Name + '.csv'
#From TechNet: The first line of the file must contain 12 items separated by commas
$firstLine = New-TermLine -TermSetName $termSet.Name -TermSetDescription $empty -LCID $empty -AvailableForTagging "TRUE" -TermDescription $empty -Level1 $empty -Level2 $empty -Level3 $empty -Level4 $empty -Level5 $empty -Level6 $empty -Level7 $empty
$terms+=$firstLine
#Now we start to add a line in the file for each term in the term set
foreach ($term in $termSet.GetAllTerms())
{
$tempTerm = $term
$counter = 0
$tempTerms = @("","","","","","","")
#this while loop makes sure you are using the root term then counts how many child terms there are
while (!$tempTerm.IsRoot)
{
$tempTerm = $tempTerm.Parent
$counter = $counter + 1
}
$start = $counter
#this makes sure that any columns that would need to be empty are empty
#i.e. if the current term is 3 levels deep, then the 4th, 5th, and 6th level will be empty
while ($counter -le 6)
{
$tempTerms[$counter] = $empty
$counter = $counter + 1
}
#start with the current term
$tempTerm = $term
#fill in the parent terms of the current term (there should never be children of the current term--the child term will have its own line in the CSV)
while ($start -ge 0)
{
$tempTerms[$start] = $tempTerm.Name
$tempTerm = $tempTerm.Parent
$start = $start - 1
}
#create a new line in the CSV file
$CSVLine = New-TermLine -TermSetName $empty -TermSetDescription $empty -LCID $empty -AvailableForTagging "TRUE" -TermDescription $empty -Level1 $tempTerms[0] -Level2 $tempTerms[1] -Level3 $tempTerms[2] -Level4 $tempTerms[3] -Level5 $tempTerms[4] -Level6 $tempTerms[5] -Level7 $tempTerms[6]
#add the new line
$terms+=$CSVLine
}
#export all of the terms to a CSV file
$terms | Export-Csv $CSVFile -notype
}
}
$taxonomySite.dispose()
}
#constructor
function New-TermLine() {
param($TermSetName, $TermSetDescription, $LCID, $AvailableForTagging, $TermDescription, $Level1, $Level2, $Level3, $Level4, $Level5, $Level6, $Level7)
$term = New-Object PSObject
$term | Add-Member -Name "TermSetName" -MemberType NoteProperty -Value $TermSetName
$term | Add-Member -Name "TermSetDescription" -MemberType NoteProperty -Value $TermSetDescription
$term | Add-Member -Name "LCID" -MemberType NoteProperty -Value $LCID
$term | Add-Member -Name "AvailableForTagging" -MemberType NoteProperty -Value $AvailableForTagging
$term | Add-Member -Name "TermDescription" -MemberType NoteProperty -Value $TermDescription
$term | Add-Member -Name "Level1" -MemberType NoteProperty -Value $Level1
$term | Add-Member -Name "Level2" -MemberType NoteProperty -Value $Level2
$term | Add-Member -Name "Level3" -MemberType NoteProperty -Value $Level3
$term | Add-Member -Name "Level4" -MemberType NoteProperty -Value $Level4
$term | Add-Member -Name "Level5" -MemberType NoteProperty -Value $Level5
$term | Add-Member -Name "Level6" -MemberType NoteProperty -Value $Level6
$term | Add-Member -Name "Level7" -MemberType NoteProperty -Value $Level7
return $term
}
Get-TermSetsCSV -SiteUrl $siteUrl -CSVOutput $outputDir
以上是关于powershell 将所有组中的所有术语集导出为CSV文件。的主要内容,如果未能解决你的问题,请参考以下文章
为大型 hdf5 文件重命名组中的所有 HDF5 数据集时出现问题
Powershell:将所有具有“NetworkRuleSet”属性的 Azure 存储帐户列出/导出到 CSV
使用 powershell 导出带有私钥的证书,包括路径中的所有证书