PowerShell for O365, PowerShell for SharePoint (on-prem), SharePoint 2013, SharePoint 2016, SharePoint Online

Create a SharePoint Taxonomy using PowerShell PnP and XML file

Today is all about SharePoint taxonomy with PowerShell PnP!

In a nutshell, taxonomy is a hierarchical group of term sets & terms, that is provided by SharePoint when configuring the Managed Metadata Service Application (MMS).
Creation of terms is done via the Term Store in SharePoint Server (when MMS is configured), and is also available in SharePoint Online.

For more information about SharePoint taxonomy, get started with the following links:


For the purpose of this post, we will create the taxonomy 1-by-1 first, and then create/import from an XML file in SharePoint Online with SharePoint PowerShell PnP (available on GitHub), but the same cmdlets are available for SharePoint Server 2013/2016.


Create the taxonomy one-by-one

We’ll start by creating the Term groups, Term sets, and Terms 1-by-1 in order to get a grasp at the cmdlets & their syntax.

First off, let’s create a Term Group by using the New-PnPTermGroup cmdlet.

#Connect to SPO
$creds = Get-Credential
Connect-PnPOnline -Url https://blogdemo123-admin.sharepoint.com/ -Credentials $creds

#Create the Term Group
New-PnPTermGroup -Name "Phones" -Description "Phones TermGroup"


Second, we’ll create a Term Set below that Term Group using the New-PnPTermSet.

New-PnPTermSet -Name "Brand" -TermGroup "Phones" -Lcid "1033"

Note: The “-Lcid” parameter is meant to be optional. However, not inserting it will throw an error “New-PnPTermSet : Specified argument was out of the range of valid values”.
This is a known issue documented on the SharePoint PnP / GitHub page.


And lastly, let’s create a Term in this Term Set using the New-PnPTerm referencing the TermGroup & TermSet.

New-PnPTerm -Name "myPowerfullPhone" -TermSet "Brand" -TermGroup "Phones" -Lcid "1033"

Note: Same as above, the “-Lcid” parameter is meant to be optional. However, not inserting it will throw an error “New-PnPTerm : Specified argument was out of the range of valid values”.
Known issue documented on the SharePoint PnP / GitHub page.


Now we have it! Let’s check out the result 🙂





Create / Import taxonomy from XML file

Now is the time to go through automation! Importing multiple Term Groups, Term Sets, and Terms contained in an XML file.
I like the XML structure because it feels neat and organised…. And a simple notepad++ is enough 🙂

We would need to know the XML syntax, but it is also possible using a .TXT format, or even arrays if you feel more comfortable this way.
Note: If you log into O365 and navigate to the Term Store, under “Sample Import”, Microsoft gives you a link to download a sample of what a .csv file would look like.

So my XML file is structured like the following:

Demo XML File

We don’t need spaces between the tags, I simply wanted to show you a clear structure if you didn’t know it 😉

Now, let’s use the Import-PnPTermGroupFromXml to get our taxonomy to SharePoint Online.
Two (2) ways to use this cmdlet:

  • Import-PnPTermGroupFromXml -Xml <xml file variable>
  • Import-PnPTermGroupFromXml -Path <location of the XML file>
Import-PnPTermGroupFromXml -Path C:\Users\$env:USERNAME\Desktop\BlogDemoTaxonomy.xml


If all went well, we should see our taxonomy in SPO!

Import Taxonomy to SPO
Taxonomy imported into SPO!



Tagged , , , ,

Leave a Reply