0

I use a Sharepoint list with 4 columns. The first column contains a date. What I would like is a ps-script that deletes every row before Todays date. Is that possible? This is what i got so far:

connect-pnponline -url xxxxxxxxxxxxxxxx -Credential $credential

Remove-PnPListItem -List "my-list" -Identity ($TheItemId)

PK

0

Please test the PnP script in TEST area before applying to PROD

#Get the items that are older than Today
$items = Get-PnPListItem -List "Contact" -Query "<View><ViewFields><FieldRef Name='Title'/></ViewFields><Query><Where><Leq><FieldRef Name='StartDate'/><Value Type='DateTime'><Today/></Value></Leq></Where></Query></View>"


$items.Count

foreach($item in $items) 
  {
    write-host "removing item: " $item.Id

    Remove-PnPListItem -List "Contact" -Identity $item.Id -Force
    
  }


Your Answer

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