0

I am using a PS script mentioned here: https://www.sharepointdiary.com/2016/11/sharepoint-online-import-terms-to-termset-using-powershell.html to import the terms from a csv file to the term store.

#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://***-admin.sharepoint.com/"
$TermGroupName= "Site Collection - ****.sharepoint.com-sites-Home"
$TermSetName="****"
$CSVFile ="C:\Users\Desktop\ImportTermSet.csv"
$TermHeaderInCSV ="Level 1 Term"

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
    $TaxonomySession=[Microsoft.SharePoint.Client.Taxonomy.TaxonomySession]::GetTaxonomySession($Ctx)
    $TaxonomySession.UpdateCache()
    $TermStore =$TaxonomySession.GetDefaultSiteCollectionTermStore()
    $Ctx.Load($TaxonomySession)
    $Ctx.Load($TermStore)
    $Ctx.ExecuteQuery()

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

        #Get the Term Group
        $TermGroup=$TermStore.Groups.GetByName($TermGroupName)

        #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
        $Ctx.Load($Terms)
        $Ctx.ExecuteQuery()
        $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())
            $Ctx.Load($Term)
            $Ctx.ExecuteQuery()
            $Term.TermStore.CommitAll()
            $TaxonomySession.UpdateCache()
            Write-host "New Term '$TermName' Added Successfully!" -ForegroundColor Green
        }
        else
        {
            Write-host "Term '$TermName' Exists Already!" -ForegroundColor Yellow
        }
    }
 }
Catch {
    write-host -f Red "Error Importing Term store Data!" $_.Exception.Message
}

However I am kept on getting below error, enter image description here

can someone help me with the fix, the account I am using is listed as tenant admin FYI.

3

1 Answer 1

1

A few things you can check to narrow down the issue:

  1. Make sure you are using the latest version of SharePoint Online Management Shell and execute the commands as Administrator.

  2. Make sure the user you use to run the commands is a member of Term Store Administrators.

  3. Check your DNS configuration, which is suggested in the other post already.
  4. Disable IPV6 if it is in use on your machine. Switch to another end for a test if possible.

Reference:

Fixing the “For security reasons DTD is prohibited in this XML document.” issue.

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.