SharePoint OnlinePowerShell Export TermSets

Iron Contributor

Hello.

 

I have the following script to export termset data:

 

#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\WindowsPowerShell\Modules\SharePointPnPPowerShellOnline\3.28.2012.0\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\WindowsPowerShell\Modules\SharePointPnPPowerShellOnline\3.28.2012.0\Microsoft.SharePoint.Client.Runtime.dll"
Add-Type -Path "C:\Program Files\WindowsPowerShell\Modules\SharePointPnPPowerShellOnline\3.28.2012.0\Microsoft.SharePoint.Client.Taxonomy.dll"
   
#Variables for Processing
$AdminURL = "https://tenant-admin.sharepoint.com/"
$TermGroupName = "My Term Sets"
$TermSetName = "Contact Type"
$CSVFile="C:\Term Sets\TermSetData-ContactType.csv"
 
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) 
    $TermStore =$TaxonomySession.GetDefaultSiteCollectionTermStore()
    $Ctx.Load($TaxonomySession)
    $Ctx.Load($TermStore)
    $Ctx.ExecuteQuery()
 
    #Get the Term Group
    $TermGroup=$TermStore.Groups.GetByName($TermGroupName)
 
    #Get the term set
    $TermSet = $TermGroup.TermSets.GetByName($TermSetName)
 
    #Get all tersm from the term set
    $Terms = $TermSet.Terms
    $Ctx.Load($Terms)
    $Ctx.ExecuteQuery()
 
    Write-Output $TermsetName > $CSVFile
    #Export Terms to CSV
    Foreach($Term in $Terms)
    {
        Write-Output $Term.Name >> $CSVFile
    }     
    Write-host "Term Set Data Exported Successfully!" -ForegroundColor Green
}
Catch {
    write-host -f Red "Error Exporting Term Set!" $_.Exception.Message
}

 

However I'm receiving the following error that I have NO IDEA how to remedy:

 

Error Exporting Term Set! Cannot convert argument "context", with value: "Microsoft.SharePoint.Client.ClientContext", for "GetTaxonomySession" to type "Microsoft.SharePoint.Client.ClientRuntimeContext": "Cannot convert the "Microsoft.SharePoint.Client.ClientContext" value of type "Microsoft.SharePoint.Client.ClientContext" to type "Microsoft.SharePoint.Client.ClientRuntimeContext"."

 

Is Microsoft.SharePoint.Client.ClientContext supposed to be a file?? I don't have that on my machine anywhere anywhere. I tried researching but didn't find anything. Surprise, was this error just made for me and no one else runs into this type of issue?

 

I'm simply trying to get an export of my termsets, I kind've figured it'd be wayyyy to easy to find a script and adjust file locations to my setup. 

 

Any thoughts?

 

0 Replies