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

[玩转系统] SharePoint Online:使用 PowerShell 删除内容类型

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

SharePoint Online:使用 PowerShell 删除内容类型


要求:从 SharePoint Online 网站删除内容类型。

如何删除 SharePoint Online 中的内容类型?

您是否曾经创建过 SharePoint Online 内容类型并决定不再需要它?或者当您遇到问题并需要删除并重新创建特定内容类型时想要永久删除它?在本文中,我们将引导您完成在 SharePoint Online 中删除内容类型的步骤。我们还将分享用于删除 SharePoint Online 中的内容类型的 PowerShell。

可以删除列表或库未使用的内容类型。要删除 SharePoint Online 中的内容类型,请执行以下步骤:

  1. 登录到您的 SharePoint Online 站点 >> 单击站点设置齿轮 >> 站点设置。
  2. 在网站设置页面中,单击“网站内容类型”。
  3. 在“网站内容类型”页面下,单击要删除的内容类型的名称。
  4. 单击“删除此网站内容类型”链接并确认一次提示。

    [玩转系统] SharePoint Online:使用 PowerShell 删除内容类型

在 SharePoint Online 中使用 PowerShell 删除内容类型:

请记住,删除内容类型是一项永久性操作(无法撤消!) - 在继续之前请确保您确实不需要它!以下是用于删除 SharePoint Online 中的内容类型的 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 Delete-ContentType()
{ 
    param
    (
        [Parameter(Mandatory=$true)] [string] $SiteURL,
        [Parameter(Mandatory=$true)] [string] $ContentTypeName
    )

    Try {
        $Cred= Get-Credential
        $Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

        #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()
        
        #Check if the content type exists in the site        
        $ContentType = $ContentTypeColl | Where {$_.Name -eq $ContentTypeName}
        If($ContentType -eq $Null)
        { 
            Write-host "Content Type '$ContentTypeName' doesn't exists in '$SiteURL'" -f Yellow
        }
        else
        {
            #delete the content type
            $ContentType.DeleteObject()
            $Ctx.ExecuteQuery() 

            Write-host "Content Type '$ContentTypeName' deleted successfully!" -ForegroundColor Green
        }
  }
    Catch {
        write-host -f Red "Error Deleting Content Type!" $_.Exception.Message
    } 
}

#Set parameter values
$SiteURL="https://crescent.sharepoint.com"
$ContentTypeName="Projects"

#Call the function
Delete-ContentType -SiteURL $SiteURL -ContentTypeName $ContentTypeName

用于删除 SharePoint Online 中的内容类型的 PnP PowerShell

让我们看看如何使用 PnP PowerShell cmdlet Remove-PnPContentType 删除 SharePoint Online 中的内容类型:


#Config Variables
$SiteURL = "https://Crescent.sharepoint.com"
$ContentTypeName ="Project Proposal V1"

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)

#Get the content type
$ContentType = Get-PnPContentType -Identity $ContentTypeName

If($ContentType)
{ 
    Remove-PnPContentType -Identity $ContentTypeName -Force 
}

无法删除 SharePoint Online 中的内容类型?
无法删除内容类型?获取“另一个网站或列表仍在使用此内容类型。如果您仍想删除它,请从所有网站和列表中删除该内容类型,然后重试。”错误?嗯,这可能是因为您可能有与您尝试删除的内容类型关联的列表或库。解决方案如下:SharePoint Online 无法删除内容类型

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

取消回复欢迎 发表评论:

关灯