Completely remove whole meetings’ SERIES using PowerShell and EWS.

Hey!

Some time ago I’ve published here a way to remove meetings from calendars using EWS:

https://paweljarosz.wordpress.com/2017/10/09/exchange-online-remove-cancelled-outlook-meetings-using-powershell-and-ews/

I got a bit upset that I needed to run the script from time to time to remove old stalled  cancelled meetings that were there before applying “AutoAccept” calendar processing. We got tons of them believe me, and I wanted to get rid of them completely! But how to remove the whole series and not just meetings for like two years, I wanted not to worry about the meetings even after 5 years, I just didn’t know how to remove the whole series as when people were mentioning about removing the series in the Internet articles, they were usually mentioning how to remove meetings for a long period of time and were calling it by removing a “series”.

After few hours of searching, I’ve found an answer here:

https://gsexdev.blogspot.com/2012/02/ews-managed-api-and-powershell-how-to.html

I won’t write here the whole script, the main idea is the samem there is just a little difference.

When you read the item from the calendar by:

$AllCalendarItems = $ExchService.FindAppointments($CalendarFolder.Id,$CalendarView)

And you create a loop to process them:

foreach($CalendarItem in AllCalendarItems.Items){

Do not work on these items, no! no no no..NO! 🙂

Instead of that, do something like this in the loop:

$CalendarItemRecurringMasters += [Microsoft.Exchange.WebServices.Data.Appointment]::BindToRecurringMaster($exchservice,$CalendarItem.Id)

This line is the key here, as Glens says on his website:

There is no method for BindToRecurringMaster on the appointment object you need to use it like
[Microsoft.Exchange.WebServices.Data.Appointment]::BindToRecurringMaster($service,$Appointment.Id)

Now you got an array with all the recurring masters ^^, make it contains only unique records (as otherwise when performing a delete on item that is not there you will got an error) ,and NOW on THOSE items, go ahead with the hard delete part:

foreach($CalendarItemRecurringMaster. in $CalendarItemRecurringMasters){
$CalendarItemRecurringMaster.Delete([Microsoft.Exchange.WebServices.Data.DeleteMode]::HardDelete)

nice

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s