当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 修复 SharePoint Online 中的“另一个网站或列表仍在使用此内容类型”错误

作者:精品下载站 日期:2024-12-14 21:05:27 浏览:16 分类:玩电脑

修复 SharePoint Online 中的“另一个网站或列表仍在使用此内容类型”错误


问题:尝试从列表或网站中删除内容类型时,我在 SharePoint Online 网站中收到以下错误:
“另一个网站或列表仍在使用此内容类型。如果您仍想删除它,请从所有网站和列表中删除该内容类型,然后重试。“

[玩转系统] 修复 SharePoint Online 中的“另一个网站或列表仍在使用此内容类型”错误

解决方案:

查找使用特定内容类型的引用,并从列表中删除内容类型关联。 (您必须删除特定内容类型的项目或更改项目的内容类型才能从列表中删除内容类型关联)。另外,请从第一阶段(最终用户)回收站和第二阶段(管理员)回收站中删除项目!

用于在 SharePoint Online 中查找内容类型用法的 PowerShell:

此 PowerShell 脚本扫描并导出网站集中的内容类型引用。


#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

Function Get-ContentTypeUsage()
{ 
    param
    (
        [Parameter(Mandatory=$true)] [string] $SiteURL,
        [Parameter(Mandatory=$true)] [string] $ContentTypeName,
        [Parameter(Mandatory=$true)] [string] $ReportFile        
    )

    Try {
        $Cred= Get-Credential
        $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
        Write-host "Processing Site:"$SiteURL
        #Setup the context
        $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
        $Ctx.Credentials = $Credentials
    
        #Get the content type from web
        $ContentTypeColl = $Ctx.Web.ContentTypes
        $Ctx.Load($ContentTypeColl)
        $Ctx.ExecuteQuery()
        
        #Array to hold result
        $Results = @()

        #Get all lists and libraries from the site
        $Ctx.Load($ctx.Web.Lists)
        $Ctx.Load($Ctx.Web.Webs)
        $Ctx.ExecuteQuery()

        Foreach($List in $Ctx.Web.Lists)
        {
            $Ctx.Load($List.ContentTypes)
            $Ctx.ExecuteQuery()
       
            #Check if the content type exists in the list        
            $ContentType = $List.ContentTypes | Where {$_.Name -eq $ContentTypeName}
            If($ContentType -ne $Null)
            { 
                $Results += New-Object PSObject -Property @{
                'Site' = $SiteURL
                'List Name' = $List.Title
                'URL'= $SiteURL+$List.DefaultViewURL
                }
                Write-host "Found Content Type Reference at '$($List.Title)' in site '$SiteURL'" -f Green
            }
        }
        #Export Results to CSV
        $Results | Export-Csv $ReportFile -Append -NoTypeInformation

        #Process subsites - Call the function recursively
        If($Ctx.Web.Webs.Count -gt 0)
        {
            Foreach ($web in $Ctx.Web.Webs)
            {
                Get-ContentTypeUsage -SiteURL $web.Url -ContentTypeName $ContentTypeName -ReportFile $ReportFile
            }
        }
  }
    Catch {
        write-host -f Red "Error Deleting Content Type!" $_.Exception.Message
    }
}

#Set parameter values
$SiteURL="https://crescent.sharepoint.com/"
$ContentTypeName="Project Template"
$ReportFile="C:\Temp\ContentTypeRef.csv"

#Delete the Output report file if exists
if (Test-Path $ReportFile) { Remove-Item $ReportFile }

#Call the function
Get-ContentTypeUsage -SiteURL $SiteURL -ContentTypeName $ContentTypeName -ReportFile $ReportFile

以下是针对 SharePoint 本地部署的类似解决方案:如何解决 SharePoint 中的内容类型使用错误?

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯