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
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
Always use the EstimateResultOnly parameter first, before deleting the content. Just in case your query is not right ;)
Hello,
How can I delete one meeting event in share calendar in specific time and date?
I run
Remove-CalendarEvents -Identity “1017/1018 – Saint George (20 Seats)” -CancelOrganizedMeetings -QueryStartDate “07/28/2020 1:00 PM”
But it didn’t accept it. I ran it in the my exchange server 2016.
thank you
-DeleteContent parameter is not working or even avialable in the latest RU for Exchange 2010, is there any work around? I have a user with over 15,000 calendar items I wish to remove. Help!!!
Hi,
Is this command possible for a group?
everytime I receive an error that the groupname couldn’t be found on a DC. The group are on the DC’s.
Search-Mailbox –identity username –SearchQuery Subject:”holidays” –DeleteContent
Regards Wouter
Hi,
this command delete a holiday for 1 user.
How can I do it for all users? is it possible by user group?
Search-Mailbox -identity ‘user’ -SearchQuery Subject:”holidayname” -DeleteContent
Regard Wouter
Dude, you rock!!!
Thanks Luis.
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?
Thank you Rajith,
That was really helpful. You rock :)
Thanks Miguel.
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?
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”.
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
Please paste the error you are getting SJ and we can look more into it.
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
HI SJ,
You are not closing “, which starts after -SearchQuery.