@Mike Sharp , Thanks for the update.
Did you delete the content type directly from the Content Type Hub before you unpublish it via Site Content Types > the published Content Type > Manage publishing for this content type > Unpublish?
If that is the scenario, you need to recreate the old content type in the Content Type Hub with the same name and GUID, so that you can unpublish it and have the system remove it from all sites.
Here is a sample PowerShell script to recreate the content type in CTH for your reference:
function New-SPOContentType {
param(
[Parameter(Mandatory=$true,Position=1)]
[string]$Username,
[Parameter(Mandatory=$true,Position=2)]
$AdminPassword,
[Parameter(Mandatory=$true,Position=3)]
[string]$Url,
[Parameter(Mandatory=$true,Position=4)]
[string]$Description,
[Parameter(Mandatory=$true,Position=5)]
[string]$Name,
[Parameter(Mandatory=$true,Position=6)]
[string]$Group,
[Parameter(Mandatory=$true,Position=7)]
[string]$ParentContentTypeID
)
$ctx = New-Object Microsoft.SharePoint.Client.ClientContext($Url)
$ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Username, $(convertto-securestring $AdminPassword -asplaintext -force))
$ctx.ExecuteQuery()
$lci = New-Object Microsoft.SharePoint.Client.ContentTypeCreationInformation
$lci.Description = $Description
$lci.Name = $Name
$lci.ID = $ContentTypeID
#paramters.Id and parameters.ParenetContentType cannot be used together.
#$lci.ParentContentType=$ctx.Web.ContentTypes.GetById($ParentContentTypeID)
$lci.Group = $Group
$ContentType = $ctx.Web.ContentTypes.Add($lci)
$ctx.Load($contentType)
try {
$ctx.ExecuteQuery()
Write-Host "Content Type " $Name " has been added to $AdminUrl" -foregroundcolor green
}
catch [Net.WebException]{
Write-Host $_.Exception.ToString()
}
}
# Paths to SDK
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"
# Parameters
$Username = "<admin@tenant.onmicrosoft.com>"
$AdminPassword = "<password>"
$AdminUrl = "https://<tenant>.sharepoint.com/sites/contentTypeHub/"
$Description = "<Description>"
$Name = "<Original Name>"
$ParentContentTypeID = "0x0120D520"
$ContentTypeID = "0x0120D52000EF84D53385206F439993CB193716595A" #Same in all sites
$Group = "Custom Content Types"
New-SPOContentType -Username $Username -AdminPassword $AdminPassword -Url $AdminUrl -Description $Description -Name $Name -Group $Group -ParentContentTypeID $ParentContentTypeID
References: Contenttype hub publishing old (deleted) content types. / SharePoint Online content types in Powershell: Add.
Hi @Mike Sharp ,do you have any progress on this thread? Please feel free to let us know if you need further assistance.
I've been able to recreate two of the three "phantom" content types, but one of them throws an exception when I try to create it:
Exception calling "ExecuteQuery" with "0" argument(s): "The parent content type specified by content type identifier
0x01010095EBB3997D0F6A49BDE1C248D336D150 does not exist."
I could see that the parent should be "[...]336D150" so I created a parent first, then created the child "[...]336D15001"
I think this is probably why my original content types weren't working. Somehow I lost the parent for the type.
Anyway, once I did this, two more content types showed up under with an ID pattern like "[...]336D15002", and I created those using the same powershell and unpublished them as well. I'll let you know if it works, but so far it looking good!
Thanks for your assistance!
Yes, this worked! I had to do it several times in order to get rid of everything. Thanks for the suggestion!
Note to anyone else in this situation: We have MFA turned on in our tenant, so the simplest way to execute the powershell above is to create an App Password to use with it.
Glad to know your problem is solved, and thanks a lot for the additional information.
Sign in to comment