0

Is it possible to delete the last 20 rows of a sharepoint list with a powershell script? I use the module pnppowershell.

Gr.

P

1 Answer 1

2

Please follow the steps:

1.This is a test SharePoint list:

enter image description here

2.Please run the below PowerShell script as an admin:

$SiteURL = "https://domain.sharepoint.com/sites/sitename"
$ListName = "listname"
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)
#Get the last 20 row items
$Items = Get-PnPListItem -List $ListName | select -Last 20
ForEach ($Item in $Items)
{
   $ItemID = $Item["ID"]   
   $ItemID
   #Remove the item and saves it in the Recycle Bin
   Remove-PnPListItem -List $ListName -Identity $ItemID -Force -Recycle
   Write-Host "Delete the Item Title : " $Item["Title"] 
}

enter image description here

3.Here is my test:

enter image description here

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.