How to delete calendar items from SharePoint online calendar list using PowerShell?

Download the SP online management shell.

You can either go with the default SP online PowerShell commands or the PnP way. To get the PnP commands, install the PnP module by invoking

Install-Module SharePointPnPPowerShellOnline

And then connect to your site using

Connect-PnPOnline –Url https://yoursite.sharepoint.com –Credentials (Get-Credential)

Now, to retrieve all the calendar items, tweak the following command:

$listItems = Get-PnPListItem -List Calendar -Query "<View><Query><Where><Eq><FieldRef Name="EventDate" /><Value Type="DateTime"><Today /></Value></Eq></Where></Query></View>"

The above command lists all the events for today. Add your conditions for the date fields to get your collection.

I have not tried retrieving recurring events before, so I believe you might need to play with the columns “RecurrenceID”, “fRecurrence” and(or) “RecurrenceData”. Check this article for more details.

Now when you are sure that all the retrieved items are as per the condition and this is exactly what you would like to copy or delete, then add a for loop to copy or delete them.

foreach($item in $listItems) {
        #Create object
    $itemVal = @{       
        'Title' = $item('Title')
        ...........
        .........
    }
    Add-PnPListItem -List 'newCalendarlist' -Values $itemVal -ContentType "Item"
}

And for the delete command, get the list item ids and pass it on in a for loop.

Remove-PnPListItem -List "Demo List" -Identity "1"