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

[玩转系统] 如何使用 CSOM-PowerShell 删除 SharePoint Online 中的列表?

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

如何使用 CSOM-PowerShell 删除 SharePoint Online 中的列表?


要求:使用 PowerShell 删除 SharePoint Online 中的列表。

重要提示:在继续之前,请确保您已在客户端计算机上安装了 SharePoint Online 客户端运行时。从这里下载:https://www.microsoft.com/en-us/download/details.aspx?id=42038

用于删除 SharePoint Online 中的列表的 PowerShell 脚本:

如果您需要删除 SharePoint Online 中不再需要的列表,您可以使用 PowerShell,而不是通过 Web 界面。在本文中,我们将向您展示如何使用 PowerShell 删除 SharePoint Online 中的列表。


#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"
  
##Variables for Processing
$SiteUrl = "https://crescent.sharepoint.com"
$ListName="Projects"

#Get Credentials to connect
$Cred= Get-Credential

#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 List
$List = $Context.web.Lists.GetByTitle($ListName)
$Ctx.Load($List)
$List.DeleteObject()
$Ctx.ExecuteQuery()
Write-Host "List deleted Successfully!"

在 PowerShell ISE 中运行它:

[玩转系统] 如何使用 CSOM-PowerShell 删除 SharePoint Online 中的列表?

您也可以使用此 PowerShell 在 SharePoint Online 中删除文档库。如果列表受到保护不被删除怎么办?那么,您必须设置“AllowDeletion”属性才能启用删除。更多信息请参见此处:如何使用 PowerShell 删除 SharePoint Online 中的列表?

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

取消回复欢迎 发表评论:

关灯