powershell 删除列表或库中的所有SharePoint列表项
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell 删除列表或库中的所有SharePoint列表项相关的知识,希望对你有一定的参考价值。
$cnt = 0
$i = 0
$startDate = Get-Date
# Enter your configuration here
$webUrl = "https://xxxx"
$listName = "Workflow History"
write-host "Opening web at $webUrl..."
$web = Get-SPWeb $webUrl
$batchSize = 8000
write-host "Web is: $($web.Title)"
$list = $web.Lists[$listName];
write-host "List is: $($list.Title)"
$spQuery = New-Object Microsoft.SharePoint.SPQuery
$spQuery.ViewAttributes = "Scope='Recursive'";
$spQuery.RowLimit = $batchSize
$caml = '<OrderBy Override="TRUE"><FieldRef Name="ID"/></OrderBy>'
$spQuery.Query = $caml
$cntDeleted = 0
$listItems = $list.GetItems($spQuery)
$batch = "<?xml version=`"1.0`" encoding=`"UTF-8`"?><Batch>"
$i = 0
foreach ($item in $listItems)
{
$i++
write-host "`rProcessing ID: $($item.ID) ($i of $batchSize)" -nonewline
$batch += "<Method><SetList Scope=`"Request`">$($list.ID)</SetList><SetVar Name=`"ID`">$($item.ID)</SetVar><SetVar Name=`"Cmd`">Delete</SetVar><SetVar Name=`"owsfileref`">$($item.File.ServerRelativeUrl)</SetVar></Method>"
}
$batch += "</Batch>"
write-host
write-host "Sending batch..."
# We execute it
$result = $web.ProcessBatchData($batch)
write-host "Emptying Recycle Bin..."
# We remove items from recyclebin
$recycleCount = $web.RecycleBin.Count
write-host "$recycleCount items in the Recycle Bin"
$web.RecycleBin.DeleteAll()
$list.Update()
write-host "Done."
$endDate = Get-Date
New-TimeSpan $startDate $endDate
$web = get-spweb https://xxxx
$list = $web.Lists["109 Projects"]
$cntDeleted = 0
$cnt = 0
foreach($item in $list.Items)
{
$cnt++
$item["ProjectStage"]
if($item["ProjectStage"] -eq "Completed" -or $item["ProjectStage"] -eq "Cancelled"){
$list.getitembyid($item.id).Delete()
$itemText = $item["ProjectStage"]
write-host "$itemText deleted"
$cntDeleted++
}
else
{
}
}
write-host "deleted $cntDeleted out of $cnt"
if(-not(Get-PSSnapin | where { $_.Name -eq "Microsoft.SharePoint.PowerShell"}))
{
Add-PSSnapin Microsoft.SharePoint.PowerShell;
}
$web = get-spweb http://portal.opwftg.com/sites/OPWSS/Teams/OCM
$list = $web.lists | where {$_.title -eq "PublicFolderAtt"}
Write-host "List $($list.title) has $($list.items.count) entries"
$items = $list.items
foreach ($item in $items)
{
Write-host " Say Goodbye to $($item.id)" -foregroundcolor red
$list.getitembyid($Item.id).Delete()
}
以上是关于powershell 删除列表或库中的所有SharePoint列表项的主要内容,如果未能解决你的问题,请参考以下文章
在项目或库中找不到清单中引用的类
powershell 获取SharePoint库中所有文件夹的列表,包括子文件夹
powershell 这将使用PowerShell从库中删除SharePoint中特定文件夹和子文件夹中的文件
powershell Powershell SharePoint下载库中的所有文件。
Powershell从SharePoint文档库中删除文件
powershell 获取位于“页面”库中的所有页面并更改其页面布局。