Introduction
In this article, you will learn how we can create, retrieve and delete the site content types on SharePoint sites, using PnP PowerShell. The Client Side Object Model is used internally for these operations. The update operation is not available for the content types.
Prerequisite
You need to have PowerShell 3.0, available on a Windows machine. You need to install or import PnP PowerShell packages. You can download the installers or view more documentation on the official site. The installers are available here.
The following operations will be compatible with SharePoint 2013 on-premise or Office 365 versions.
Connect To Site
Connect to the site, using the snippet given below. The PnP PowerShell code, given below, helps in getting the current context of the site, using the Client Side Object Model (CSOM).
- #Get Current Context Site (Root)
- $siteurl = "https://abc.sharepoint.com"
- Connect-SPOnline -Url $siteurl
- $ctx = Get-SPOContext
Once connected, you can carry out any of the operations mentioned below, based on the requirement.
Create Site Content Type
The content types can be added to the site collections by setting the context, using the site URL. PnP CSOM PowerShell can be used to complete the operation.
Add-SPOContentType command is used to create the site content types on SharePoint sites. The required parameters to create the new site content type are name, description and group. The new values can be passed as the parameters. In my example, I have created new site content called "PnPContentType". The default parent content type will be the item.
The following command snippet helps to create the new content type.
- function AddContentType(){
- Add-SPOContentType -Name "PnPContentType" -Description "PnP Content Type" -Group "PnPContentTypeGroup"
- }
- AddContentType # Create New Content Type with name, description
The parent content type can be used as a base content type to create the new content types. The following example shows to create the new content type, using the page content type, given below:
- function AddContentTypeUsingCT(){
- $pageCT = Get-SPOContentType -Identity Page
- Add-SPOContentType -Name "PnPPageContentType" -Description "PnP Content Type" -Group "PnPContentTypeGroup" -ParentContentType $pageCT
- }
- AddContentTypeUsingCT # Create New Content Type with name, description using page content type

- function RetrieveContentTypes(){
- Get-SPOContentType
- }
- RetrieveContentTypes # Retrieves all the content types from site level
- function RetrieveContentTypeByName(){
- Get-SPOContentType -Identity "Item"
- }
- RetrieveContentTypeByName # Retrieves the content type from site using name

- function RetrieveContentTypeById(){
- Get-SPOContentType -Identity 0x01
- }
- RetrieveContentTypeById # Retrieves the content type from site using id
- function RetrieveSiteCTfromList(){
- Get-SPOContentType -List "PnPList"
- }
- RetrieveSiteCTfromList # Retrieves the site content type from particular list
- function RemoveContentType(){
- Remove-SPOContentType -Identity "PnPContentType" –Force
- }
- RemoveContentType # Delete the content type from site using name
Thus, you have learned how to create, retrieve or delete the site content types from SharePoint sites, using PnP PowerShell on SharePoint 2013 / SharePoint online sites.

kalu singh raoPosted Jul 12, 2016, 1:49 AM
Nice...