Friday, 28 December 2018

SharePoint CSOM Taxonomy

I completely enjoyed many scripts in Taxonomy which I might release as a eBook later.
Below is one Taxonomy code in CSOM which helps you to get the HashTags:

$taxonomySession = [Microsoft.SharePoint.Client.Taxonomy.TaxonomySession]::GetTaxonomySession($context);
$termStore = $taxonomySession.GetDefaultSiteCollectionTermStore();
$hashTerms=$termStore.HashTagsTermSet.GetAllTerms()
$Context.Load($hashTerms)
$Context.ExecuteQuery()
$hashTerms|%{Write-Host $_.Name}

Before you run the above script, ensure you are connected and downloaded the necessary dlls.Connect by changing the User and SiteURL to your values.
#Download Sharepoint online client components
#Specify tenant admin and site URL
$User = "admin@xxx.onmicrosoft.com"
$SiteURL = "https://xxx.sharepoint.com/sites/dev"
#Add references to SharePoint client assemblies
$spPath="C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\"
Add-Type -Path ($spPath+"Microsoft.SharePoint.Client.dll")
Add-Type -Path ($spPath+"Microsoft.SharePoint.Client.Runtime.dll")
Add-Type -Path ($spPath+"Microsoft.SharePoint.Client.Search.dll")
Add-Type -Path ($spPath+"Microsoft.SharePoint.Client.Taxonomy.dll")
Add-Type -Path ($spPath+"Microsoft.SharePoint.Client.Publishing.dll")
Add-Type -Path ($spPath+"Microsoft.SharePoint.Client.UserProfiles.dll")
$Password = Read-Host -Prompt "Please enter your password" -AsSecureString
$Creds = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($User,$Password)
#Bind to site collection
$Context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Context.Credentials = $Creds

No comments:

Post a Comment