PowerShell :: Delete All List Items

Leave a Comment
Hi All,
In a following post we will see about a PowerShell Script which is used to delete all SharePoint List Items.

Code Snippet:

[CmdletBinding()]
Param(
[Parameter(Mandatory=$true)][System.String]$Url,
[Parameter(Mandatory=$true)][System.String]$ListName
)

if(!(Get-PSSnapin Microsoft.SharePoint.PowerShell -ea 0))
{
Add-PSSnapin Microsoft.SharePoint.PowerShell
}


$Web = Get-SPWeb $Url
$List = $Web.lists[$ListName]
if($List -eq $null){
    Write-Error "The List cannot be found";return
}
Write-Warning "Deleting all list items from $($ListName)"
$Items = $List.GetItems()
$Items | ForEach-Object{
$List.GetItemById($_.Id).Delete()
}
$List.Update()
$Web.Dispose()
Write-Host "Job Done"

You can download the same code from the below link,


Thanks.

Related Post

0 comments:

Post a Comment