1

I have just typed 1000 terms, and term sets into my dev environment in 2013. I now you can import csv files, but the question, is how can I export them from the dev environment, so that I can easily import them into other environments. I need that it uses the same guids.

thx

1
  • Is exporting / importing the managed metadata service an option? If so you would keep all terms, termsets and termgroups with correct ID:s Jul 31 '13 at 10:32
1

There doesn't exist a User-interface function to do this, how ever through the power of PowerShell this is possible.

Mercedes Bernard has made a brilliant blog which includes PowerShell script about how to export Term Sets.

Andreas Wijaya has taken Mercedes Bernard's PowerShell script and altered it a bit to match his needs for it, but both works very well.

Both export the Term Sets in to CSV files.

Code from Andreas' blog:

Add-PSSnapin "Microsoft.SharePoint.PowerShell"

 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)
         {
             if ($termSet.Name -eq "Your Term Set Name")
             {
             $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 "Your Site" -CSVOutput "C:\"
2
  • what about the guids, later I need to create a feature that connect fields to termsets, and normally I would need the guid of the term , or I only need the term name? blog.tippoint.net/… Jul 31 '13 at 10:25
  • @LuisValenciaMunoz They will receive new GUIDs once imported to the new site. There exist PowerShell scripts as well to get the GUIDs, C#/VB scripts too.
    – user2536
    Jul 31 '13 at 10:31
3

This is the powershell code I used in my project and it exports the guids as well. I think is a simplier way

EXPORT

$mmsProxy = Get-SPServiceApplicationProxy | ?{ $_.DisplayName -eq "Managed Metadata Service" }

$mmsApp = Get-SPServiceApplication | ?{ $_.DisplayName -eq "Managed Metadata Service" }

$mmsAppID = $mmsApp.Id

Export-SPMetadataWebServicePartitionData -Identity $mmsAppID -ServiceProxy $mmsProxy -Path C:\mms_origen.bak

IMPORT

$mmsProxy = Get-SPServiceApplicationProxy | ?{ $_.DisplayName -eq "Managed Metadata Service" }
$mmsApp = Get-SPServiceApplication | ?{ $_.DisplayName -eq "Managed Metadata Service" }
$mmsAppID = $mmsApp.Id
Import-SPMetadataWebServicePartitionData -Identity $mmsAppID -ServiceProxy $mmsProxy -Path C:\mms_origen.bak –OverwriteExisting

Remember to change the literal "Managed Metadata Service" by the name of your Managed Metadata Service Application.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.