Remove All Items in List using MS PnP Powershell – SharePoint Online


I am sharing the below power shell snippet to help my fellows to remove all items in a list in the SharePoint online. Often we need to delete items at once using power shell or through JS code. PNP Power shell make it more easier to complete our task. (hats off)

Copy and paste the below code, it will loop through to a list and remove the item. Change the List name as yours.

Connect-PnPOnline –Url https://*********************

$items =Get-PnPListItem -List “ListName” -PageSize 1000

foreach ($item in $items)
{
try
{
Remove-PnPListItem -List “ListName” -Identity $item.Id -Force
}
catch
{
Write-Host “error”
}

} #for each end

To install PNP Power shell check the PnP PowerShell overview.

#Sharing is caring

Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s