Forum Discussion
How to delete all calendar appointments booked by terminated users?
You can use PowerShell commands to delete all calendar appointments booked by terminated users in your Office 365 environment. Here are the steps to do this:
Connect to Office 365 PowerShell using the following command:
Connect-ExchangeOnline -UserPrincipalName <UPN of a global administrator>
Next, use the following command to get all terminated users:
$terminatedUsers = Get-User -Filter {UserAccountControl -eq "AccountDisabled" -and RecipientTypeDetails -eq "UserMailbox"}
For each terminated user, you need to give full access permission to their mailbox using the following command:
Add-MailboxPermission -Identity <Terminated User's email address> -User <Your Email Address> -AccessRights FullAccess -InheritanceType All
Once you have full access to the terminated user's mailbox, you can use the following command to delete all calendar appointments booked by the user:
Search-Mailbox -Identity <Terminated User's email address> -SearchQuery 'kind:calendar' -DeleteContent -Force
Finally, you can send an email to all attendees to inform them about the deleted meeting using the following command:
Send-MailMessage -To <Attendee email addresses> -Subject "Meeting Cancellation" -Body "The meeting booked by a terminated user has been cancelled." -SmtpServer <SMTP server name>
Note: Before performing any of these steps, please make sure you have appropriate permissions and have tested the commands in a non-production environment. Also, ensure that you have a backup of all the data before you delete anything.
Bharat_Mishra thanks for the response. We are intentionally looking to delete a departed employee's calendar appts quietly and NOT SEND OUT a notice to all attendees. As previous mentioned, when I used a similar script to delete a departed employee's calendar appts it automatically sent a cancellation notice out to both internal and EXTERNAL parties. This departed employee was a recruiter and had lots of past and future appts on the calendar for people he scheduled interviews with that were not hired at Hazel. When the cancelled meetings when out to them they asked what was going on with it and made us look pretty silly. Also, for some ex-employees who was the organizer of lots of meetings, even our internal staff do not want to receive the massive flurry of emails for cancelled meetings. Having a way to delete them without sending a cancellation notice out would be very helpful.