[玩转系统] 修复 SharePoint Online 上的“处于保留或保留策略状态时无法删除列表”错误
作者:精品下载站 日期:2024-12-14 21:16:48 浏览:15 分类:玩电脑
修复 SharePoint Online 上的“处于保留或保留策略状态时无法删除列表”错误
问题:尝试删除 SharePoint Online 中的文档库时,出现错误消息:“列表在保留或保留策略期间无法删除。”
解决方案:
正如错误消息所示:在保留或保留策略期间无法删除列表。此错误是由于该网站处于保留或保留政策之下。因此,要删除该列表,您必须先删除其所有文件和子文件夹。否则,您应该删除 Office 365 合规中心下的保留策略。您可以通过以下方式快速检查网站是否被冻结:
- 管理中心 >> 安全与合规 >> 搜索与调查
- 单击“电子数据展示”,然后检查您是否已创建任何案例 >> 如果您看到任何案例,请单击“打开”
- 在“保留”下,检查是否看到任何站点。
删除每个文件夹中的文件可能会令人难以忘怀,尤其是对于深层文件夹结构。幸运的是,我们有 PowerShell 来减轻负担。
PowerShell清除文档库的内容然后删除
此 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
$SiteURL = "https://crescent.sharepoint.com/Sites/Marketing"
$LibraryName = "Branding Templates"
#Function to Delete all files and Sub-folders of a given Folder
Function Empty-SPOFolder([Microsoft.SharePoint.Client.Folder]$Folder)
{
Try {
#Get All Files from the Folder
$Files = $Folder.Files
$Ctx.Load($Files)
$Ctx.ExecuteQuery()
#Iterate through each File in the folder
Foreach($File in $Files)
{
#Delete the file
$Folder.Files.GetByUrl($File.ServerRelativeUrl).Recycle() | Out-Null
Write-host -f Green "Deleted File '$($File.Name)' from '$($File.ServerRelativeURL)'"
}
$Ctx.ExecuteQuery()
#Process all Sub Folders of the given folder
$SubFolders = $Folder.Folders
$Ctx.Load($SubFolders)
$Ctx.ExecuteQuery()
Foreach($Folder in $SubFolders)
{
#Exclude "Forms" and Hidden folders
If( ($Folder.Name -ne "Forms") -and (-Not($Folder.Name.StartsWith("_"))))
{
#Call the function recursively to empty the folder
Empty-SPOFolder -Folder $Folder
#Delete the folder
$Ctx.Web.GetFolderById($Folder.UniqueId).Recycle() | Out-Null
$Ctx.ExecuteQuery()
Write-host -f Green "Deleted Folder:"$Folder.ServerRelativeUrl
}
}
}
Catch {
write-host -f Red "Error:" $_.Exception.Message
}
}
Try {
#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 Library
$Library = $Ctx.web.Lists.GetByTitle($LibraryName)
$RootFolder = $Library.RootFolder
$Ctx.Load($Library)
$Ctx.Load($RootFolder)
$Ctx.executeQuery()
#Call the function to empty Folder
Empty-SPOFolder $RootFolder
#Delete the Document Library
$Library.Recycle() | Out-Null
$Ctx.ExecuteQuery()
Write-host -f Green "Deleted Document Library Successfully!"
}
Catch {
write-host -f Red "Error:" $_.Exception.Message
}
使用“文件资源管理器”视图一次性删除 SharePoint Online 文档库中的所有文件和文件夹!使用 PnP PowerShell 删除保留保留中的文档库
让我们通过先删除所有文件和文件夹,然后使用 PnP PowerShell 删除文档库来修复 SharePoint Online 上的“在保留或保留策略时无法删除列表”错误。请注意,如果文件已签出,则无法删除它!必须将其签入才能删除。 PowerShell 批量签入 SharePoint Online 中的所有文档
#Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/Marketing"
$ListName = "Branding Templates"
#Connect to the Site
Connect-PnPOnline -URL $SiteURL -Credentials (Get-Credential)
#Get the web & document Library
$Web = Get-PnPWeb
$List = Get-PnPList -Identity $ListName
#Function to delete all Files and sub-folders from a Folder
Function Empty-PnPFolder([Microsoft.SharePoint.Client.Folder]$Folder)
{
#Get the site relative path of the Folder
If($Folder.Context.web.ServerRelativeURL -eq "/")
{
$FolderSiteRelativeURL = $Folder.ServerRelativeUrl
}
Else
{
$FolderSiteRelativeURL = $Folder.ServerRelativeUrl.Replace($Folder.Context.web.ServerRelativeURL,[string]::Empty)
}
#Get All files in the folder
$Files = Get-PnPFolderItem -FolderSiteRelativeUrl $FolderSiteRelativeURL -ItemType File
#Delete all files in the Folder
ForEach ($File in $Files)
{
#Delete File
Remove-PnPFile -ServerRelativeUrl $File.ServerRelativeURL -Force -Recycle
Write-Host -f Green ("Deleted File: '{0}' at '{1}'" -f $File.Name, $File.ServerRelativeURL)
}
#Process all Sub-Folders
$SubFolders = Get-PnPFolderItem -FolderSiteRelativeUrl $FolderSiteRelativeURL -ItemType Folder
Foreach($SubFolder in $SubFolders)
{
#Exclude "Forms" and Hidden folders
If( ($SubFolder.Name -ne "Forms") -and (-Not($SubFolder.Name.StartsWith("_"))))
{
#Call the function recursively
Empty-PnPFolder -Folder $SubFolder
#Delete the folder
$ParentFolderURL = $FolderSiteRelativeURL.TrimStart("/")
Remove-PnPFolder -Name $SubFolder.Name -Folder $ParentFolderURL -Force -Recycle
Write-Host -f Green ("Deleted Folder: '{0}' at '{1}'" -f $SubFolder.Name, $SubFolder.ServerRelativeURL)
}
}
}
#Get the Root Folder of the Document Library and call the function to empty folder contents recursively
Empty-PnPFolder -Folder $List.RootFolder
#Now delete the document library
Remove-PnPList -Identity $ListName -Recycle -Force
Write-host -f Green "Document Library Deleted Successfully!"
如果您只想清除文档库而不删除库,请注释行#50 - Remove-PnPList。这是关于从文档库中删除所有文件和文件夹的另一篇文章:SharePoint Online:如何使用 PowerShell 删除文档库中的所有文件?
PnP PowerShell 清空 SharePoint Online 文档库
上面的脚本适用于小于 5000 个文件的较小库。但在较大的库上,它会收到“Get-PnPFolderItem:尝试的操作被禁止,因为它超出了列表视图阈值。”错误,因为 Get-PnPFolderItem 无法处理大型列表和库。因此,这是通过使用 PnP 批处理方法更快地删除文档库中的所有文件和文件夹来清空文档库的备用脚本:
#Parameters
$SiteURL = "https://crescent.sharepoint.com/sites/Inventory"
$ListName = "Branding Templates"
Try {
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive
$List = Get-PnPList $ListName
$ItemCount = $List.ItemCount
If($ItemCount -eq 0) { Write-host "Document Library is Already Empty!" -f Yellow; Break}
#Get All Items from the Library
$global:counter = 0
$ListItems = Get-PnPListItem -List $ListName -PageSize 500 -Fields ID -ScriptBlock { Param($items) $global:counter += $items.Count; Write-Progress -PercentComplete `
($global:Counter / $ItemCount * 100) -Activity "Getting Items from List" -Status "Getting Items $global:Counter of $($ItemCount)"}
Write-Progress -Activity "Completed Getting Items from Library $($List.Title)" -Completed
#Sort List Items based on Server Relative URL - Descending
$SortedItems = $ListItems | Select-Object @{Name="ServerRelativeURL";Expression={$_.FieldValues.FileRef}}, ID | Sort-Object -Descending -Property ServerRelativeURL
#Delete List Items in the Batch
$Batch = New-PnPBatch
ForEach ($Item in $SortedItems)
{
Remove-PnPListItem -List $ListName -Identity $Item.ID -Recycle -Batch $Batch
#Write-host "Deleted Item:"$Item.ServerRelativeURL
}
Invoke-PnPBatch -Batch $Batch -Details
Write-host -f Green "All Items in the Library deleted Successfully!"
}
Catch {
write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
}
猜你还喜欢
- 03-30 [玩转系统] 如何用批处理实现关机,注销,重启和锁定计算机
- 02-14 [系统故障] Win10下报错:该文件没有与之关联的应用来执行该操作
- 01-07 [系统问题] Win10--解决锁屏后会断网的问题
- 01-02 [系统技巧] Windows系统如何关闭防火墙保姆式教程,超详细
- 12-15 [玩转系统] 如何在 Windows 10 和 11 上允许多个 RDP 会话
- 12-15 [玩转系统] 查找 Exchange/Microsoft 365 中不活动(未使用)的通讯组列表
- 12-15 [玩转系统] 如何在 Windows 上安装远程服务器管理工具 (RSAT)
- 12-15 [玩转系统] 如何在 Windows 上重置组策略设置
- 12-15 [玩转系统] 如何获取计算机上的本地管理员列表?
- 12-15 [玩转系统] 在 Visual Studio Code 中连接到 MS SQL Server 数据库
- 12-15 [玩转系统] 如何降级 Windows Server 版本或许可证
- 12-15 [玩转系统] 如何允许非管理员用户在 Windows 中启动/停止服务
取消回复欢迎 你 发表评论:
- 精品推荐!
-
- 最新文章
- 热门文章
- 热评文章
[短剧] 2025年05月31日 精选+付费短剧推荐58部
[软件合集] 25年5月31日 精选软件66个
[电影] 黄沙漫天(2025) 4K.EDRMAX.杜比全景声 / 4K杜比视界/杜比全景声
[风口福利] 短视频红利新风口!炬焰创作者平台重磅激励来袭
[韩剧] 宝物岛/宝藏岛/金银岛(2025)【全16集】【朴炯植/悬疑】
[电影] 愤怒的牦牛 (2025) 国语中字 4k
[短剧合集] 2025年05月30日 精选+付费短剧推荐56部
[软件合集] 25年5月30日 精选软件26个
[软件合集] 25年5月29日 精选软件18个
[短剧合集] 2025年05月28日 精选+付费短剧推荐38部
[剧集] [央视][笑傲江湖][2001][DVD-RMVB][高清][40集全]李亚鹏、许晴、苗乙乙
[电视剧] 欢乐颂.5部全 (2016-2024)
[电视剧] [突围] [45集全] [WEB-MP4/每集1.5GB] [国语/内嵌中文字幕] [4K-2160P] [无水印]
[影视] 【稀有资源】香港老片 艺坛照妖镜之96应召名册 (1996)
[剧集] 神经风云(2023)(完结).4K
[剧集] [BT] [TVB] [黑夜彩虹(2003)] [全21集] [粤语中字] [TV-RMVB]
[资源] B站充电视频合集,包含多位重量级up主,全是大佬真金白银买来的~【99GB】
[影视] 内地绝版高清录像带 [mpg]
[书籍] 古今奇书禁书三教九流资料大合集 猎奇必备珍藏资源PDF版 1.14G
[美图] 2W美女个美女小姐姐,饱眼福
[电视剧] [突围] [45集全] [WEB-MP4/每集1.5GB] [国语/内嵌中文字幕] [4K-2160P] [无水印]
[剧集] [央视][笑傲江湖][2001][DVD-RMVB][高清][40集全]李亚鹏、许晴、苗乙乙
[电影] 美国队长4 4K原盘REMUX 杜比视界 内封简繁英双语字幕 49G
[电影] 死神来了(1-6)大合集!
[软件合集] 25年05月13日 精选软件16个
[精品软件] 25年05月15日 精选软件18个
[绝版资源] 南与北 第1-2季 合集 North and South (1985) /美国/豆瓣: 8.8[1080P][中文字幕]
[软件] 25年05月14日 精选软件57个
[短剧] 2025年05月14日 精选+付费短剧推荐39部
[短剧] 2025年05月15日 精选+付费短剧推荐36部
- 最新评论
-
- 热门tag