I am using PnP to set up a number of site collections with the same set of site columns and content types. Initially I created an XML provisioning file from a site I set up, but when I applied it to another site there were issues adding the content types and creating some site columns that were using the term store to lookup values. So now I am trying to set up the site columns and content types using Pnp PowerShell instead.

I could use some help translating some of the fields in the provisioning xml file to a PnP PowerShell command.

I wonder how to specify the -ID, should I use curly brackets or not? And how should I specify the -TermSetPath? In the term store, I have a node XXX, where I have the term set Classification accessible for all sites in my hub. But since this is not open for everyone to add terms, I am planning on finding some PnP command to move those locally for each site. So I will store "Classification" under the "Site Collection - xx.xxx.com-sites-thisSite" node. In the provisioning xml this is specified as {termsetid:{sitecollectiontermgroupname}:Classification}. How do I specify that to the Pnp command?

This is what I got:

The PnP PowerShell command: Add-PnPTaxonomyField -DisplayName "Classification" -InternalName "Classification" -Group "XXX" -ID "cd165a06-9295-438b-90ef-20786be3a1fc" -TermSetPath "TestTermGroup|TestTermSet"

From the provisioning XML file:

<Field Type="TaxonomyFieldType" DisplayName="Classification" List="{{listid:TaxonomyHiddenList}}" WebId="{siteid}" ShowField="Term1033" Required="FALSE" EnforceUniqueValues="FALSE" Group="XXX" ID="{cd165a06-9295-438b-90ef-20786be3a1fc}" SourceID="{{siteid}}" StaticName="Classification" Name="Classification" Description="'Classification' is used to specify ...">
                <Value xmlns:q1="http://www.w3.org/2001/XMLSchema" p4:type="q1:string" xmlns:p4="http://www.w3.org/2001/XMLSchema-instance">{sitecollectiontermstoreid}</Value>
                <Value xmlns:q2="http://www.w3.org/2001/XMLSchema" p4:type="q2:string" xmlns:p4="http://www.w3.org/2001/XMLSchema-instance">{termsetid:{sitecollectiontermgroupname}:Classification}</Value>

And there is also another field generated in the provisioning xml, that seems coupled with the field I am trying to add. Do I need to add this field as well?
<Field Type="Note" DisplayName="Classification_0" StaticName="cd165a069295438b90ef20786be3a1fc" Name="cd165a069295438b90ef20786be3a1fc" ID="{72bd59fd-153c-4ab6-b49b-c40cd77853c8}" ShowInViewForms="FALSE" Required="FALSE" Hidden="TRUE" CanToggleHidden="TRUE" SourceID="{{siteid}}" />

And (a bonus question) the List="{{listid:TaxonomyHiddenList}}" from the provisioning xml file, how is that translated to the PnP command? Do I need to resolve listid to something?


You donot have to specify the -ID parameter for PnP PowerShell command :Add-PnPTaxonomyField. ID will be generated automatically when you create the column.

For -TermSetPath parameter, it should be like this "<Group Name>|<Term Set name>". If you store "Classification" under the "Site Collection - xx.xxx.com-sites-thisSite" node. The TermSetPath shoule be "Site Collection - xx.xxx.com-sites-thisSite|Classification".

Reference: https://www.c-sharpcorner.com/article/create-termset-and-taxonomy-field-using-pnp-powershell/

  • I thought I needed to add ID to get the same ID for this site column on all my site collections?
    – Gunilla
    Oct 16 '20 at 11:31

Try this:

$DisplayName = "Departments"
Add-PnPTaxonomyField -List $List -DisplayName $DisplayName -InternalName $DisplayName -TaxonomyItemId f076462d-bde7-4fa4-aa7b-4409a769fcd1

Source: https://sposcripts.com/add-sharepoint-columns-with-powershell/#Add_Managed_Metadata_Column

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.