Delete All Calendar Entries In An Exchange 2010 Mailbox

Share & Comment

A question came via email asking to help with deleting all calendar entries in an Exchange 2010 mailbox. Let’s find out how to do it.

The calendar in question had thousands of entries and hence the exchange admin wanted to clear it all using PowerShell. A one-liner will do the job, provided that you know how to filter the calendar entries alone in a mailbox ;)

This question came in response to my article about how to delete all items in the recoverable items folder in an Exchange 2010 mailbox. We will use the same cmdlet along with an advanced query syntax to filter only the calendar entries.

The command to run is as follows.

Search-Mailbox –identity username –SearchQuery kind:meetings –DeleteContent

You can get an estimate about the number of entries and size that will be freed up after deletion by running

Search-Mailbox –identity username –SearchQuery kind:meetings –EstimateResultOnly

Estimate meetings in a mailbox

Similarly, you can delete contacts, notes, tasks, im & emails by changing the search query.

Search-Mailbox –identity username –SearchQuery kind:contacts –DeleteContent

Search-Mailbox –identity username –SearchQuery kind:notes –DeleteContent

Search-Mailbox –identity username –SearchQuery kind:tasks –DeleteContent

Search-Mailbox –identity username –SearchQuery kind:im –DeleteContent

Search-Mailbox –identity username –SearchQuery kind:email –DeleteContent

Estimate im in a mailbox

Always use the EstimateResultOnly parameter first, before deleting the content. Just in case your query is not right ;)

Share & Comment
Subscribe for Updates
Never miss a blog post again

9 comments… add one

  1. SJ

    Great! Thanks for this Rajith, it’s what I’ve been looking for. Can you tell me, are you able to modify the script so it only deletes Calendar entries older than 2 years say?

    1. Rajith Jose Enchiparambil

      Hi SJ,

      I am not in front of an Exchange server now, but you should be able to give a date range in the “Search Query”.

      1. SJ

        Hi Rajith,

        Thank you for the replay, I appreciate your time. I must have tried a hundred combinations of this, with limited success.

        The following works sometimes but it wipes everything, the range seems to get ignored:

        [PS] C:\>Search-Mailbox -Identity e10test1 -SearchQuery “kind:meetings AND Received:> $(’12/09/2013 00:00:00′) AND Received: < $('20/09/2013 23:59:59')" -DeleteContent -force

        I tried the following but I get positional parameter errors:

        [DateTime]
        $DT = (Get-Date).AddDays(-30).ToString("d")
        Search-Mailbox e10test1 –SearchQuery kind:meetings, received:< $DT –DeleteContent -force

        Note: I use the dd/mm/yyyy format for Australia.

        Any advise would be welcome.

        Cheers!

        SJ

        1. Rajith Jose Enchiparambil

          Please paste the error you are getting SJ and we can look more into it.

          1. SJ

            Sure.
            For this one I’ve created a ps1 file and pasted:
            [DateTime]
            $DT = (Get-Date).AddDays(-30).ToString(“d”)
            Get-Mailbox e10test1 –SearchQuery “kind:meetings, received:.\caldelete2.ps1

            IsPublic IsSerial Name BaseType
            ——– ——– —- ——–
            True True DateTime System.ValueType
            A positional parameter cannot be found that accepts argument ‘-SearchQuery’.
            + CategoryInfo : InvalidArgument: (:) [Get-Mailbox], ParameterBindingException
            + FullyQualifiedErrorId : PositionalParameterNotFound,Get-Mailbox

            for this one:
            PS] C:\>Search-Mailbox -Identity e10test1 -SearchQuery “kind:meetings AND Received:> $(’12/09/2013 00:00:00′) AND Received: >

            This second one I’d prefer to get running so that I may specify a date range.

            Note: running exchange 2010 SP2 RU6

            Much appreciated!

            SJ

            1. Rajith Jose Enchiparambil

              HI SJ,

              You are not closing “, which starts after -SearchQuery.

  2. Miguel Alcocer

    Thank you Rajith,

    That was really helpful. You rock :)

    1. Rajith Jose Enchiparambil

      Thanks Miguel.

  3. Mike

    Rajith, I have been trying to use Search-Mailbox –identity username –SearchQuery kind:contacts –DeleteContent to delete all contacts from a mailbox that has 606,325 contacts (duplicates)

    When I run the command I get the error ” A positional parameter cannot be found that accepts argument ‘-DeleteContent’”

    I have also run the command search-mailbox -identity alias -searchquery kind:contacts -targetmailbox myaddress -targetfolder inbox -logonly -loglevel full to see what would be found by the search query.

    I get the following error message from EMS “The search on mailbox CN=users name,OU=Users,DC=Mydomain did not complete because the search folder timed out.”
    The log also comes to my inbox as failed with no items found.

    could this be failing because of the large amount of contacts or am I doing something wrong?

Leave a Comment