Clean Up Orphaned Calendar Items in Exchange 2007

Updated 3/29/2012

A common problem I’ve read about, and personally experienced, is deleting a user and their mailbox, only to find out later that they had a recurring calendar meeting in a conference room, or they were an administrative assistant, or something like that. This will cause orphaned calendar items that can be a pain to clean up. When I recently ran into this problem, I noodled around trying to find an answer. I found forums on Microsoft’s site, Experts-Exchange, etc. with nothing that was really helpful. Finally, I hit up a peer of mine, Robert Durkin. Robert sent me this link of a post by Dominic Savio that got me going in the right direction.

Dominic’s post covered the basics and had the information I needed, but it still required some playing to get what I needed. So, I ended up with three commands to clean up old orphaned calendar items:

Command 1:

Export-Mailbox -Identity <user alias> -SenderKeywords “deleted_user@company.com” -IncludeFolders “\Calendar” –DeleteContent

This command will delete all calendar appointments originating from the deleted user in a single target mailbox using that deleted user’s email address. This will ensure that only calendar appointments from that user will be deleted since we’re A) using a unique string to identify the appointments and B) specifying the Calendar folder. Be careful if you’ve added the departed user’s email as an alias to another account because I didn’t test that and I am not sure what those results would be.

Command 2:

Get-Mailbox | Export-Mailbox -SenderKeywords “deleted_user@company.com” -IncludeFolders “\Calendar” –DeleteContent

This command will delete calendar appointments originating from the deleted user in every mailbox, in the unlikely event they were meeting happy.

Command 3:

Get-Mailbox -Filter {CustomAttribute14 -eq ‘ResourceMB’} | Export-Mailbox -SenderKeywords “deleted_user@company.com” -IncludeFolders “\Calendar” –DeleteContent

I borrowed the filter portion of my last post in this command to delete the appointments originating from the deleted user in every mailbox whose Custom Attribute 14 is set to ResourceMB. I went ahead and entered this custom attribute for every conference room, projector, and video cart we have so that I can clean them all up with one command.

You can also use the –TargetMailbox parameter to redirect items to a separate mailbox instead of delete them in the event of a disaster. The full list of parameters for TargetMailbox is located here.

Quick note.  I ran into a scenario where the user’s account was already deleted, so when I would run the command, it didn’t do any clean up.  When I checked the appointment, I saw that the user had ‘No e-mail address exists for this person’ in the properties in Outlook.  Since this was the case, the command using the email address obviously didn’t work.  I replaced the email address with the displayed user name in the appointment and it worked like a champ.  The modified command looked something like this:

Get-Mailbox -Filter {CustomAttribute14 -eq ‘ResourceMB’} | Export-Mailbox -SenderKeywords “Lastname, Firstname” -IncludeFolders “\Calendar” –DeleteContent

Be sure to get the ‘Lastname, Firstname” value from what is displayed in the orphaned appointment.

7 thoughts on “Clean Up Orphaned Calendar Items in Exchange 2007

  1. I have a problem in that the user account names here had spaces in them which caused problems with another product. All users now have new accounts, but their firstname, lastname, email address have stayed the same. Now I can’t use your commands to delete as the names have stayed the same. Ideas?

  2. @Matt: Do you have a working version of this for Office365? I’ve got a couple different things to try here, but I just wanted to single out a few specific meetings. We have a current situation where the user is still active, and I’d like to not delete their prior meetings, but would like to preemptively clear out recurring meetings that will happen 2 months after a certain date. Is there a away to do this?

  3. I know this is older but I just ran into this problem. The user has been deleted from ad and exchange. I tried writing
    Get-Mailbox -Filter {CustomAttribute14 -eq ‘ResourceMB’} | Export-Mailbox -SenderKeywords “Lastname, Firstname” -IncludeFolders “\Calendar” –DeleteContent
    However I get “cannot bind parameter “filer” to the target. Any suggestions?

    1. @Ryan – the CustomAttribute portion of this post was referring to an earlier post where I discussed Resource Mailbox maintenance. That command will only work if you’ve utilized the Custom Attribute and set it in mailboxes you want to manage.

Leave a comment