Welcome to an a blog on how to connect SharePoint managed metadata, using PowerShell script. In our projects, we are sometimes required to retrieve 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 SharePoint managed metadata database very quickly and efficiently.
Steps
- Open Windows PowerShell modules as an administrator.
- Paste the code, mentioned below 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 parameters, mentioned above 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 the data in any metadata Service database. Here, in this article, we saw how to connect SharePoint managed metadata database, using PowerShell script.