Welcome to an article on how to connect SharePoint Managed Metadata using PowerShell script. In our projects we sometimes require to fetch the data from SharePoint Managed Metadata DB and use it in our projects.
We will see a very simple executable script which will allow you to connect to the SharePoint Managed Metadata database very quickly and efficiently.
Steps
- Open Windows PowerShell Modules as an Administrator.
- Paste the following code as .ps1 file and execute it.
Code
- #Add the PowerShell snap in code
- Add-PSSnapIn Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue | Out-Null
- #Provide a site collection to load the metadata properties from the SharePoint Central Admin where you metadata Database is connected
- $siteCollectionUrl = "http://devlink /"
- $site =new-object Microsoft.SharePoint.SPSite($siteCollectionUrl)
- #Get the Taxanomy
- $session = New-Object Microsoft.SharePoint.Taxonomy.TaxonomySession($site)
- #Get the Termstore
- $termStore = $session.TermStores[0]
- #Provide the term store group you want to load and get connected
- $group = $termStore.Groups["Test"]
- #Provide the termset you want to load
- $termSet = $group.TermSets["Test1"]
- #Get all the desired terms.
- $terms = $termSet.GetAllTerms()
- Write-Host "SharePoint Connected"
Pre-requisites - Site Collection URL
- Name of the Term Store Group
- Name of the Term set
The above parameters are required from your end while connecting to the metadata database. Once you get the correct parameters and execute the script , you will get a message “SharePoint Connected”.
Here we are using the term group Test and trying to fetch the term set called as Test1. Similarly, you can use the script to connect any Term group or term set as per your requirement.
This connection can be used to view or edit data in any Metadata Service Database. Here in this article we saw how to connect SharePoint Managed Metedata Database using PowerShell Script.