6

How do I import a CSV file to metadata service using PowerShell? The CSV file has 500 rows and seven levels in it (Importing of term store).

1 Answer 1

8

This is the PS script I'm using:

    Param([string]$CentralAdminURL, [string]$TermsCSV, [string]$ADGroup)

    cls
    # loading the term store
    $site = Get-SPSite -Identity($CentralAdminURL)
    $session = new-object Microsoft.SharePoint.Taxonomy.TaxonomySession($site)
    $termstore = $session.TermStores[0]

    # Create a Taxonomy Group
    # I first create a Term Group
    $termGroup = "MY MM Group"
    $group = $termstore.CreateGroup($termGroup)
    $termstore.AddTermStoreAdministrator($ADGroup)
    $group.AddGroupManager($ADGroup)
    $termstore.CommitAll()
    # Import Taxonomy "Know How"
    # Create an instance of ImportManager
    $Importer = $termstore.GetImportManager()
    $varImported = ""
    $varMessages = ""
    $TermSetReader = [System.IO.File]::OpenText($TermsCSV)

    # Syntax: ImportTermSet(TermGroup, TextReader, out isImported, out errorMessage)
    $termset = $Importer.ImportTermSet($group ,$TermSetReader, ([REF] $varImported), ([REF] $varMessages))
    $termset.set_Owner($ADGroup)
    $termset.TermStore.CommitAll()
    Write-Host $varMessages
    Write-Host $varImported
    $site.Dispose()

adapted from the original at http://stevenderveaux.wordpress.com/2010/04/09/import-taxonomy-csv-file-via-powershell/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.