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

[玩转系统] SharePoint Online:如何使用 PowerShell 删除列表模板?

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

SharePoint Online:如何使用 PowerShell 删除列表模板?


要求:删除 SharePoint Online 中的列表模板。

如何删除 SharePoint Online 列表模板?

如果您是 SharePoint Online 用户,您就会知道列表模板是创建新 SharePoint Online 列表时节省时间的好方法。但是如果您想删除列表模板怎么办?在这篇博文中,我们将讨论删除列表模板所需的步骤。我们还将向您展示如何使用 PowerShell 删除 SharePoint Online 中的列表模板。

要删除 SharePoint Online 中的列表模板,请执行以下操作:

  1. 登录到您的 SharePoint Online 网站集(列表模板的范围仅限于网站集级别)>> 单击“设置”>>“网站设置”
  2. 在“网站设置”页面上,单击“Web 设计师库”下的“列表模板”(https://Tenant.sharepoint.com/sites/SiteURL/_catalogs/lt/Forms/AllItems.aspx)
  3. 选择要删除的列表模板,然后单击功能区中的“删除文档”
  4. 确认删除 SharePoint Online 中的自定义列表模板的提示。

    [玩转系统] SharePoint Online:如何使用 PowerShell 删除列表模板?

SharePoint Online:用于删除列表模板的 PowerShell

您可能不时需要删除列表模板,所以让我们看看如何使用 PowerShell 在 SharePoint Online 中删除列表模板:


#Load SharePoint Online 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"
    
#Variables for Processing
$SiteUrl = "https://crescent.sharepoint.com/sites/Projects"
$ListTemplateInternalName= "Project Tasks.stp"

#Get Credentials to connect
$Cred= Get-Credential
  
Try {    
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
    $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
     
    #Get the Web
    $Web = $Ctx.Web
    $Ctx.Load($Web)
    $Ctx.ExecuteQuery()
    
    #Get the List Template
    $ListTemplateFile = $Web.GetFileByURL("_catalogs/lt/" + $ListTemplateInternalName)
    $Ctx.Load($ListTemplateFile)
    $Ctx.ExecuteQuery()

    If($ListTemplateFile -ne $Null)
    {
        $ListTemplateFile.Recycle()
        $Ctx.ExecuteQuery()
        Write-host -f Green "List Template Deleted Successfully!"
    }
}
catch {
    write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}

用于删除 SharePoint Online 中的列表模板的 PnP PowerShell:

要删除列表模板,首先,您需要使用 PowerShell 连接到 SharePoint Online。接下来,您可以使用Remove-PnPFile cmdlet 删除列表模板。此 cmdlet 需要 -SiteRelativeURL 参数,该参数是要删除的列表模板的名称。


#Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/IC"
$ListTemplateInternalName= "IC Documents.stp"

#Connect to the Site
Connect-PnPOnline -URL $SiteURL -Interactive

#Get the List Template
$TemplateFile = Get-PnPFolderItem -FolderSiteRelativeUrl "_catalogs/lt" -ItemName $ListTemplateInternalName

If ($TemplateFile -ne $null)
{   
    #Delete the List Template
    Remove-PnPFile -SiteRelativeUrl ("/_catalogs/lt/"+$ListTemplateInternalName) -Recycle -Force
    Write-host -f Green "List Template Deleted Successfully!"
}
Else
{
    Write-host -f Yellow "Template Not Found!"
}

总之,您可以按照上述几个简单步骤删除 SharePoint Online 中的列表模板。此外,还可以使用 PowerShell 删除 SharePoint Online 中的列表模板。请记住,您必须拥有网站所有者权限才能删除列表模板。

要创建新的列表模板,请参阅:如何使用 PowerShell 在 SharePoint Online 中创建列表模板?

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

取消回复欢迎 发表评论:

关灯