Hey SharePoint Fam,
I have a document library that I need to just totally remove that has 300k documents. Of course I am not able to delete one by one and was wondering if there is a script or tool I could use to simply delete all files or just delete the entire library all together.
I've tried following script but get runtime exception errors
Blockquote
Add-PSSnapin Microsoft.SharePoint.Powershell -ea SilentlyContinue
## SP URL
Write-Host "Provide SharePoint URL:" -ForegroundColor Yellow
$webURL = Read-Host
$web = Get-SPweb "http://domain/subsite"
## LIST NAME
Write-Host "Enter name of the list:" -ForegroundColor Yellow
$listName = Read-Host
$list = $web.lists["libraryname"]
## SET QUERY
$query = New-Object Microsoft.SharePoint.SPQuery
$query.ViewAttributes = "Scope='Recursive'"
$query.RowLimit = 1000
$query.ViewFields = "<FieldRef Name='ID'/>"
$query.ViewFieldsOnly = $true
## EXECUTE
do
{
$listItems = $list.GetItems($query)
$query.ListItemCollectionPosition = $listItems.ListItemCollectionPosition
foreach ($item in $listItems)
{
Write-Host "Deleting Item - $($item.Id)" -ForegroundColor Yellow
$list.GetItemById($item.Id).delete()
}
}
while ($null -eq $query.ListItemCollectionPosition)
Write-Host "Script finished." -ForegroundColor Green