How to add new Content Types to SharePoint Online Document Libraries using PowerShell

Learn Expert

I recently had to add a new content type to a number of SharePoint Online Document libraries and wanted to use PowerShell to simplify the process.  Having used OfficeDev PnP quite extensively in the past, I've decided to utilize it.  I was leveraging the command

 

Add-SPOContentTypeToList -ContentType $NewCType -List $lib.title -Web $w -DefaultContentType

 

Interestingly, my results were not what I expected to see.  The new content type got added as the default one and the pre existing ones (Word, Excel, PowerPoint) got removed.  This was expected as the default document types  are not true content types.  

 

However, when tried adding the default content types back, they got added to the document library but were not showing up in the New menu.  I read a few articles that talked about this problem being related to the ordering of the content types.  As the order was not importan to me, I decided to cheat a little...

 

I added all the content types I neededas Default Content Types.  What is important is that the last one I added was in fact the one I want to be the default.  By adding a content type to the document library and making it the default, it forced SharePoint to display it in the New menu.

 

Hopefully this little trick will help some of you.

-Haniel

1 Reply

I would the Get-SPOProvisioningTemplate command and the Apply-SPOProvisioingTemplate. That lists all fields and content types in an xml. Simply update and reapply the xml to the root site of your site collection and the content type is created.

 

Then for the in the subsites libraries do the same export/import. All you would need is a content type reference included in the list instances. This ensures that you will use the site collection content  types created in the above step.