I am trying to create Term with PowerShell in SharePoint Online to do so I have written below code but on [Microsoft.SharePoint.Client.Taxonomy.TaxonomySession]::GetTaxonomySession($spContext)
statement it throws an error in both of the below options,
Option 01
$User = "[email protected]"
$Site = "https://tenant.sharepoint.com/sites/home"
$GroupName = "Group"
$TermSetName = "Term Set"
#Add references to SharePoint client assemblies and authenticate to Office 365 site - required for CSOM
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"
$Password = Read-Host -Prompt "Please enter your password" -AsSecureString
# Bind to MMS
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($Site)
$Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($User,$Password)
$Context.Credentials = $Creds
$MMS = [Microsoft.SharePoint.Client.Taxonomy.TaxonomySession]::GetTaxonomySession($Context)
$Context.Load($MMS)
$Context.ExecuteQuery()
Option 2
$User = "[email protected]"
$Site = "https://tenant.sharepoint.com/sites/home"
$GroupName = "Group"
$TermSetName = "Term Set"
#Add references to SharePoint client assemblies and authenticate to Office 365 site - required for CSOM
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"
$Password = Read-Host -Prompt "Please enter your password" -AsSecureString
$spContext = New-Object Microsoft.SharePoint.Client.ClientContext($Site)
$credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($User,$Password)
$spContext.Credentials = $credentials
$web = $spContext.Web
$site = $spContext.Site
$spContext.Load($web)
$spContext.Load($site)
$spContext.ExecuteQuery()
$MMS = [Microsoft.SharePoint.Client.Taxonomy.TaxonomySession]::GetTaxonomySession($spContext)
$Context.Load($MMS)
$Context.ExecuteQuery()
Error
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"." At C:\Ravi\TCT\WTW.TCT.3.0.6.0\TCT.SPConfiguration\TCT.SPConfiguration\Test\CreateTermTest2.ps1:38 char:1 + $MMS = [Microsoft.SharePoint.Client.Taxonomy.TaxonomySession]::GetTax ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodException + FullyQualifiedErrorId : MethodArgumentConversionInvalidCastArgument
I also did little research and got below article wherein both the article mentions that "SharePoint Client Component" has multiple version but for me, I do not have those components in my control panel.
http://prashamsabadra.blogspot.com/2016/01/office-365-sharepoint-online-exception.html