Content Type Hub – Cannot delete content type

This has been discussed many times and here is another one much loved Content Type Hub issue. 🙂

So, in SPO I’ll have some Content Types in the Content Type Hub that cannot been deleted. In the SPO Admin Center when trying to delete a Content Type is says that it cannot be deleted as it is in use.

I have tried:

  • I have tried to publish the CT, wait for +8h and then unpublish it and wait another 4-8h before trying to delete it.

  • Have emptied the primary and secondary recycle bin for each site in the tenant using PnP: Clear-PnPRecycleBinItem -All -Force

  • Via code trying to find the content type and having it removed. Below code is currently saying that the CT with a specific ID is not found on any site.


    function FindContentTypeById {
        param (
            (Parameter(Mandatory=$true))
            (string)$ContentTypeId        
        )
        
        $siteCollections = GetSites ## Get all sites in the tenant custom function
        
        foreach ($site in $siteCollections) 
        {
            $siteUrl = $($site.Url)
            Write-Host "+ Site: $siteUrl"
            ConnectPnPOnline -Url $siteUrl
    
            $lists = Get-PnPList
            foreach ($list in $lists) 
            {
                $ct = Get-PnPContentType -List $($list.Title) -Identity $ContentTypeId -ErrorAction SilentlyContinue
                if($null -ne $ct) {
                    Write-Host -ForegroundColor Yellow "    - Found CT"
                    Write-Host -ForegroundColor Yellow "      - Found: $($ct.Name) in List: $($list.Title)"
                }
            }
    
            $siteCTs = Get-PnPContentType
    
            $x = $siteCTs | Where-Object {(($_.Id).StringValue -eq ($ContentTypeId))}
            if($null -ne $x)
            {
                Write-Host "  - Found: $($x.Name) in ($site.Url)"
            }
    
            Disconnect-PnPOnline
        }
    }

I have also run code that looks for a Content Type by Name with the same result (not found).

So, any ideas what else I could do/try to have the CT deleted?