ContentTypes added to SPO using PNP PoSH not working as intended!

I’m in the process of building a large scale DMS solution for a client and part of this work is deploying a lot of content types to various libraries. I wrote the deployment scripts a couple of months ago and they have been working just fine.. or so I thought.

I’m using the PNP PowerShell cmdlets to abstract a lot of the CSOM work away from me having to do it.. after all, why reinvent the wheel? If you haven’t looked at the PNP PowerShell project then why on earth not? It makes writing scripts against SharePoint Online so much easier! (See here for more details..)

I’m using the simply named add-pnpcontenttypetolist to add an existing set of ContentTypes to a document library. The ContentTypes have already been defined in the root of the Site Collection and for the purposes of showing you the issue, I’m executing the following lines of code (after connecting to the Site of course)

Add-PnPContentTypeToList -List $docLib -ContentType “Test CTYPE A” -DefaultContentType
Add-PnPContentTypeToList -List $docLib -ContentType “Test CTYPE B”
Add-PnPContentTypeToList -List $docLib -ContentType “Test CTYPE C”
Add-PnPContentTypeToList -List $docLib -ContentType “Test CTYPE D”

Nothing earth shattering there, but when we look at our List settings afterwards, you may spot a problem.

ContentTypes list before fix

As you can see, 3 of our ContentTypes have been added, but aren’t active in the list, therefore we can’t create documents using them and if we opened the property pane for a document, we wouldn’t be able to select the content type for an item either.

I had a look around and it had been raised as an issue with the PNP team in their GitHub Issues list, but having done further testing using CSOM directly, I think we can safely say this is an underlying bug with the CSOM code rather than a PNP issue.

Luckily there is a workaround, You just need to add all of your ContentTypes to the list, then call the Set-PnPDefaultContentTypeToList against your required CType afterwards, This seems to activate all of the ContentTypes on the list as a side effect.

Set-PnPDefaultContentTypeToList -List $docLib -ContentType “Test CTYPE B”

ContentTypes list after fix

Not ideal, but a workaround will do.



Skip to comment form

    • Nigel on Tue 27 Mar 18 at 8:22 am
    • Reply

    Have added an issue to the issues list ?

      • Nigel on Tue 27 Mar 18 at 8:23 am
      • Reply

      Or added your experiences to the existing comment ?

      1. Linked in the blog post fella!

    • Kurt on Mon 27 Aug 18 at 10:44 pm
    • Reply

    The work around was working for me but after updating to the latest version of PnP, it quit working. Is anyone else experiencing that?

Leave a Reply

Your email address will not be published.


This site uses Akismet to reduce spam. Learn how your comment data is processed.