«

Mar 26

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.

Paul.

3 comments

  1. Nigel

    Have added an issue to the issues list ?

    1. Nigel

      Or added your experiences to the existing comment ?

      1. Cimares

        Linked in the blog post fella!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*