1

I have a SharePoint calendar having more than 35k items.The Calendar has data from 2011 and onwards. I would like to use PowerShell script to start removing items from 2011 to 2016 from the current calendar list and move it to newly added calendar list. So this way present calendar count would come down to under 5000 item entries. I guess we can remove items based on Created field.

Also, I would like to make sure that re occurrence events are not touched and removed from the present calendar list. I have never used PowerShell so far so if someone can help me with a detailed way to connect to SharePoint online and the script, would really appreciate that. Thanks in advance.

0

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"

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.