In this blog, we will see how we can add a custom content type in a SharePoint site using PnP PowerShell. Also, we will see how we can get a particular content type and remove it from the SharePoint site using PnP PowerShell.

Add Custom Content Type in SharePoint site

  • The following command snippet will help you to create the new content type in SharePoint site.
    1. Add-PnPContentType -Name "Custom Content Type" -Description "Use for Custom projects" -Group "Custom Content Types"
  • Also, the parent content type can be used as a base content type to create new content types. The following example shows to create the new content type, using the Project content type, given below,
    1. $projectCT = Get-PnPContentType -Identity "Project"
    2. Add-PnPContentType -Name "Custom Content Type" -Description "Use for Custom projects" -Group "Custom Content Types" -ParentContentType $projectCT

Remove Content Type from SharePoint site

  • In the following command snippet, it will remove a content type called “Project” from the current web

    Remove-PnPContentType -Identity “Project”
  • The following command snippet will remove a content type called “Project” from the current web with force

    Remove-PnPContentType -Identity “Project ” -Force,
    1. Connect-PnPOnline –Url https://yoursite.sharepoint.com –Credentials (Get-Credential)
    2. <#Add custom content type to your SharePoint site#>
    3. Add-PnPContentType -Name "Custom Content Type" -Description "Use for Custom projects" -Group "Custom Content Types"
    4. <#In the following command snippet parent content type is used as a base content type to create the new content type#>
    5. $projectCT = Get-PnPContentType -Identity "Project"
    6. Add-PnPContentType -Name "Custom Content Type" -Description "Use for Custom projects" -Group "Custom Content Types" -ParentContentType $projectCT
    7. <#Remove a content type called "Project" from the current web#>
    8. Remove-PnPContentType -Identity "Project"
    9. <#Remove a content type called "Project" from the current web with force#>
    10. Remove-PnPContentType -Identity "Project" -Force