SharePoint OnlinePowerShell Export TermSets

%3CLINGO-SUB%20id%3D%22lingo-sub-2045837%22%20slang%3D%22en-US%22%3ESharePoint%20OnlinePowerShell%20Export%20TermSets%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2045837%22%20slang%3D%22en-US%22%3E%3CP%3EHello.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20the%20following%20script%20to%20export%20termset%20data%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3E%23Load%20SharePoint%20CSOM%20Assemblies%0AAdd-Type%20-Path%20%22C%3A%5CProgram%20Files%5CWindowsPowerShell%5CModules%5CSharePointPnPPowerShellOnline%5C3.28.2012.0%5CMicrosoft.SharePoint.Client.dll%22%0AAdd-Type%20-Path%20%22C%3A%5CProgram%20Files%5CWindowsPowerShell%5CModules%5CSharePointPnPPowerShellOnline%5C3.28.2012.0%5CMicrosoft.SharePoint.Client.Runtime.dll%22%0AAdd-Type%20-Path%20%22C%3A%5CProgram%20Files%5CWindowsPowerShell%5CModules%5CSharePointPnPPowerShellOnline%5C3.28.2012.0%5CMicrosoft.SharePoint.Client.Taxonomy.dll%22%0A%20%20%20%0A%23Variables%20for%20Processing%0A%24AdminURL%20%3D%20%22https%3A%2F%2Ftenant-admin.sharepoint.com%2F%22%0A%24TermGroupName%20%3D%20%22My%20Term%20Sets%22%0A%24TermSetName%20%3D%20%22Contact%20Type%22%0A%24CSVFile%3D%22C%3A%5CTerm%20Sets%5CTermSetData-ContactType.csv%22%0A%20%0ATry%20%7B%0A%20%20%20%20%23Get%20Credentials%20to%20connect%0A%20%20%20%20%24Cred%20%3D%20Get-Credential%0A%20%20%20%20%24Credentials%20%3D%20New-Object%20Microsoft.SharePoint.Client.SharePointOnlineCredentials(%24Cred.Username%2C%20%24Cred.Password)%0A%20%0A%20%20%20%20%23Setup%20the%20context%0A%20%20%20%20%24Ctx%20%3D%20New-Object%20Microsoft.SharePoint.Client.ClientContext(%24AdminURL)%0A%20%20%20%20%24Ctx.Credentials%20%3D%20%24Credentials%0A%20%0A%20%20%20%20%23Get%20the%20term%20store%0A%20%20%20%20%24TaxonomySession%3D%5BMicrosoft.SharePoint.Client.Taxonomy.TaxonomySession%5D%3A%3AGetTaxonomySession(%24Ctx)%20%0A%20%20%20%20%24TermStore%20%3D%24TaxonomySession.GetDefaultSiteCollectionTermStore()%0A%20%20%20%20%24Ctx.Load(%24TaxonomySession)%0A%20%20%20%20%24Ctx.Load(%24TermStore)%0A%20%20%20%20%24Ctx.ExecuteQuery()%0A%20%0A%20%20%20%20%23Get%20the%20Term%20Group%0A%20%20%20%20%24TermGroup%3D%24TermStore.Groups.GetByName(%24TermGroupName)%0A%20%0A%20%20%20%20%23Get%20the%20term%20set%0A%20%20%20%20%24TermSet%20%3D%20%24TermGroup.TermSets.GetByName(%24TermSetName)%0A%20%0A%20%20%20%20%23Get%20all%20tersm%20from%20the%20term%20set%0A%20%20%20%20%24Terms%20%3D%20%24TermSet.Terms%0A%20%20%20%20%24Ctx.Load(%24Terms)%0A%20%20%20%20%24Ctx.ExecuteQuery()%0A%20%0A%20%20%20%20Write-Output%20%24TermsetName%20%26gt%3B%20%24CSVFile%0A%20%20%20%20%23Export%20Terms%20to%20CSV%0A%20%20%20%20Foreach(%24Term%20in%20%24Terms)%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20Write-Output%20%24Term.Name%20%26gt%3B%26gt%3B%20%24CSVFile%0A%20%20%20%20%7D%20%20%20%20%20%0A%20%20%20%20Write-host%20%22Term%20Set%20Data%20Exported%20Successfully!%22%20-ForegroundColor%20Green%0A%7D%0ACatch%20%7B%0A%20%20%20%20write-host%20-f%20Red%20%22Error%20Exporting%20Term%20Set!%22%20%24_.Exception.Message%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHowever%20I'm%20receiving%20the%20following%20error%20that%20I%20have%20NO%20IDEA%20how%20to%20remedy%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-applescript%22%3E%3CCODE%3EError%20Exporting%20Term%20Set!%20Cannot%20convert%20argument%20%22context%22%2C%20with%20value%3A%20%22Microsoft.SharePoint.Client.ClientContext%22%2C%20for%20%22GetTaxonomySession%22%20to%20type%20%22Microsoft.SharePoint.Client.ClientRuntimeContext%22%3A%20%22Cannot%20convert%20the%20%22Microsoft.SharePoint.Client.ClientContext%22%20value%20of%20type%20%22Microsoft.SharePoint.Client.ClientContext%22%20to%20type%20%22Microsoft.SharePoint.Client.ClientRuntimeContext%22.%22%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIs%20%3CEM%3EMicrosoft.SharePoint.Client.ClientContext%3C%2FEM%3E%20supposed%20to%20be%20a%20file%3F%3F%20I%20don't%20have%20that%20on%20my%20machine%20anywhere%20anywhere.%20I%20tried%20researching%20but%20didn't%20find%20anything.%20Surprise%2C%20was%20this%20error%20just%20made%20for%20me%20and%20no%20one%20else%20runs%20into%20this%20type%20of%20issue%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI'm%20simply%20trying%20to%20get%20an%20export%20of%20my%20termsets%2C%20I%20kind've%20figured%20it'd%20be%20wayyyy%20to%20easy%20to%20find%20a%20script%20and%20adjust%20file%20locations%20to%20my%20setup.%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAny%20thoughts%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2045837%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%20Online%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Occasional 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