I have csv file containing all the Global term set values of SharePoint 2013 taxonomy. I want to import that in SharePoint Online using powershell script. Please suggest if any powershell script is there for importing CSV file.

1 Answer 1


We can use PnP PowerShell command Import-PnPTermSet to achieve it.

Or we can also use CSOM with PowerShell to achieve it.

#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Taxonomy.dll"

#Variables for Processing
$AdminURL = "https://tenant-admin.sharepoint.com/"
$TermGroupName= "People"
$TermSetName="Job Title"
$CSVFile ="C:\Temp\ImportTerms.csv"
$TermHeaderInCSV ="JobTitle"

Try {
    #Get Credentials to connect
    $Cred = Get-Credential
    $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($AdminURL)
    $Ctx.Credentials = $Credentials

    #Get the term store
    $TermStore =$TaxonomySession.GetDefaultSiteCollectionTermStore()

    #Get Termstore data from CSV and iterate through each row
    Import-Csv $CSVFile | ForEach-Object {

        #Get the Term Group

        #Get the term set
        $TermSet = $TermGroup.TermSets.GetByName($TermSetName)

        #CSV File Header Row in Term to Add
        $TermName = $_.$($TermHeaderInCSV)

        #Check if the given term exists already
        $Terms = $TermSet.Terms
        $Term = $Terms | Where-Object {$_.Name -eq $TermName}

        If(-not $Term)
            #Create Term Set
            Write-host "Creating Term '$TermName'" -ForegroundColor Cyan
            $Term = $TermSet.CreateTerm($TermName,1033,[System.Guid]::NewGuid().toString())
            Write-host "New Term '$TermName' Added Successfully!" -ForegroundColor Green
            Write-host "Term '$TermName' Exists Already!" -ForegroundColor Yellow
Catch {
    write-host -f Red "Error Importing Term store Data!" $_.Exception.Message

Reference: SharePoint Online: Import Terms to Term Set from CSV using PowerShell

Your Answer

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

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