Forum Discussion
How to delete all calendar appointments booked by terminated users?
We have a Hybrid set up with o365 and we ahve around 150+ Meeting rooms.
How to delete all calendar appointments booked by terminated users?
Before deleting, we need to email out all attendees to make sure they know the meeting is getting removed.
We know that we can do it by enabling mailbox for terminated users and then by giving Full access permission on their mailbox and then deleting the appointments using OWA/Outlook App.
But how to do this using O365 Powershell?
Regards,
Sounder
37 Replies
- Bharat_MishraCopper Contributor
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.- b-lowCopper Contributor
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.
- alexrabbiBrass ContributorThanks Bhara_Mishra,
I just need to do this for one user
- vytasunCopper Contributor
Might be a late answer, but we used the following command to clear out meetings booked by terminated users:
Remove-CalendarEvents -Identity user@domain.com -CancelOrganizedMeetings -QueryWindowInDays 180
- SCROWLEY70Copper ContributorThis was a perfect solution and did as programed. Thanks!
- Jeffrey SuarezCopper Contributor
Open the MS Office 365 admin center - resources - Rooms & equipment - select the resource and scroll to bottom (look for Edit Exchange settings - go to mailbox delegation - Full Access -add yourself - log out of your outlook and back in for the change to take.
Now you have permission to delete the calendar entries.
- Karlos_MarCopper Contributor
Jeffrey Suarez Not exactly the answer,
If the user account does NOT exist How to find all inactive users who have booked meetings and how to cancel them and then send email notifications to attendees - CiantarcCopper Contributor
- Kiefer-joe_CoppCopper Contributor
Jeffrey Suarez thanks but an extremely long method for a large organisation.
If the user account still exists, use the Remove-CalendarEvents cmdlet: https://technet.microsoft.com/en-us/library/mt784593(v=exchg.160).aspx
That works only for cloud mailboxes though. Otherwise, you will have to use some EWS-based script to find and properly cancel the appointments. Removing them via Search-Mailbox will not send cancelcation notices.
- lanTH33462Copper Contributor
The Powershell cmdlets don't work. They are not recognized as cmdlets.
- Deleted
Thanks Vasil.
If the user account DOES NOT exists ( i.e. If the On premsise AD account is in disabled state and o365 mailbox is in softdeleted state) then How to find all inactive users that have booked meetings and how to cancel the meetings and then send email notifications to the attendees.
Any scrip will be very usefull for me
Thanks
Sounder
If the user doesnt exist, you will only be able to delete them (not cancel). There's an example script here: https://social.msdn.microsoft.com/Forums/en-US/c94b2f4b-a3a0-4006-973d-b150fae078ca/using-ews-to-cancel-a-meeting-in-a-room-mailbox?forum=exchangesvrdevelopment#bc8ad055-d79e-4aae-aeb2-61d835d200d6
Just change the method to Delete on the last line...