PowerShell: Remove duplicate calendar appointments No ratings yet.

We regularly get requests for an automated way of deleting duplicate appointments from calendars (most often caused by migration issues or mistaken mailbox imports, but there are lots of reasons that you could end up with duplicates).  So, here is a script that checks for and deletes duplicates.  As usual, it uses EWS to connect to the mailbox, and requires the EWS Managed API to work (and does not need to be run on the Exchange server – any client machine will do).

A calendar item is considered a duplicate if either of these conditions is true:

  • The iCALUID of the item matches the iCALUID of another item.  Calendar items should be unique – if a matching uid is found, no further check is made and the matched appointment is deleted.
  • The subject, start, and end time match another item.

The script works by first of all reading all the appointments, and then checking each and building up a list of any duplicates.  Once all the items have been checked, the duplicate items are deleted in bulk (in batches of 500).  Currently the script will only work for appointments, though you can use it against public folder calendars or any other as needed (by using -FolderPath and -PublicFolders parameters as necessary).

To run it against a single mailbox using the credentials of the logged in user:

.\Remove-DuplicateAppointments.ps1 -mailbox mailbox@domain.com

To run it using alternative credentials (you’ll be prompted for the credentials):

.\Remove-DuplicateAppointments.ps1 -mailbox mailbox@domain.com -Credentials (Get-Credential)

Other useful parameters (there are more, but check the script for further information):

-FolderPath: use to specify the path of the calendar to be processed (only use if not the default calendar, e.g. “\Calendar2”)
-DuplicatesTargetFolder: use to specify the folder to which any duplicates will be moved.  Folder will be created if it doesn’t exist.  If not specified, then duplicate appointments will be deleted.
-PublicFolders: this switch needs to be specified if the folder path points to a calendar in public folders (otherwise the path is relative to the mailbox)
-WhatIf: if this switch is present, no changes are made, but items that would be deleted are logged
-LogFile: information is written to this file showing what has been deleted (or would be deleted if -WhatIf is also present)


Please rate this


2 thoughts on “PowerShell: Remove duplicate calendar appointments

  1. For some reason this script doesn’t catch/act on all duplicates. It stopped at 285 duplicates for me. That’s when I had two different events that were duplicated. When one of the events, and all its duplicates, were removed it only found 89 duplicates of the first event.

    I know I had over 4000 duplicates of both events!

    I used the soon-to-be-deprecated Search-Mailbox command to remove them.

    search-mailbox -Identity “Name of User” -SearchQuery “kind:meetings AND Subject:’Topic of the duplicate events” -DeleteContent

    The script does find duplicates, it just doesn’t report the correct number of duplicates, which makes it a pain when there are thousands of duplicates, as you never know how many times you have to run the script. And, it’s also quite annoying to be asked for credentials on every run.


Leave a Reply

Your email address will not be published. Required fields are marked *