Skip to content

Delete items from SharePoint list using Powershell

November 12, 2018

[CmdletBinding()]
Param(
[Parameter(Mandatory=$true)][System.String]$Url,
[Parameter(Mandatory=$true)][System.String]$ListName
)
$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()

Advertisement

From → General, PowerShell

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: