I had a content type in my default SharePoint Content Type Hub site (https://tenant.sharepoint.com/sites/contenttypehub) which I deleted before it was completely unpublished. As noted in this post, the content type still exists in the metadata service database and it will keep reappearing in every site I create. How can I ensure this no longer happens?

2 Answers 2


I will advise you to use pnp Add-PnPContentType

link to msdn pnp



The proposed solution is to recreate the content type with the exact same name, parent and ID.

A) Download the SharePoint Online SDK from here and install it.

B) Get the ID and other details of the deleted content type with the following steps:

  1. Go to a site where the content type still exists, then go to the site settings and choose Site Content Types from the Site Settings page (URL is https://tenant.sharepoint.com/sites/sitename/_layouts/15/settings.aspx)

  2. Find the lingering content type from the list and click on it.

  3. From the URL of the lingering content type, get the value of the ctype parameter from the URL. The ID is a hexadecimal code that ends right before an &, which indicates the start of another parameter named Source.

  4. Make sure you also get the Group Name of the content type, which you find at the top of the page.

NOTE: You do not need the parent content type name or ID for this exercise.

C) Creating the PowerShell script The following script is based on the script found here here.

Open PowerShell ISE and copy the following code into the editor:

function New-SPOContentType


  $ctx=New-Object Microsoft.SharePoint.Client.ClientContext($Url)
  $ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $AdminPassword)


  $lci =New-Object Microsoft.SharePoint.Client.ContentTypeCreationInformation

  $ContentType = $ctx.Web.ContentTypes.Add($lci)

         Write-Host "Content Type " $Name " has been added to " $Url
     catch [Net.WebException]
        Write-Host $_.Exception.ToString()


    # Paths to SDK. Please verify location on your computer.
    Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
    Add-Type -Path "c:\Program Files\Common Files\microsoft shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

    # Insert the credentials and the name of the admin site
    $Username="[email protected]"
    $AdminPassword=Read-Host -Prompt "Password" -AsSecureString
    $Name="CONTOSO Marketing Picture"

    # THIS THE ID OF THE PARENT, but it will not reallt be used by the script

    $Group="CONTOSO Content Types"

    New-SPOContentType -Username $Username -AdminPassword $AdminPassword -Url $AdminUrl -Description $Description -Name $Name -Group $Group -ParentContentTypeID $ParentContentTypeID
  1. Change the line $lci.ID= and add the ID of the lingering content type.
  2. Go to the lines under the comment # Paths to SDK [...] and make sure that the path to the SDK DLLs are correct.
  3. Go to the lines under the comment # Insert the credentials and amend them with the details of the lingering content type that you obtained in section B above. Note that you can add anything into $Description, and $ParentContentTypeId. This is because the Parent Content Type ID will in fact be obtained from the ID of the lingering item itself, because they concatenate. But if you are feeling anxious, go get the ID of the parent and add it here :)
  4. Execute the entire script.

NOTE: You must use an account that doesn't use Multi Factor Authentication (MFA). I tried using an account with MFA and it does not work, even if you try using an App Password.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.