I have this code to remove the last 5 rows of a Sharepoint list and it works fine. But when i change -Last to -First it does not remove the first 5 rows. What is wrong with the code?
$SiteURL = "xxxxxxx"
$ListName = "xxxxxx"
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)
$ListItems = Get-PnPListItem -List $ListName -PageSize 2000
#Get the last 20 row items
$Items = Get-PnPListItem -List $ListName | select -Last 6
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"]
}
Gr P.