Forum Discussion

Deleted's avatar
Deleted
Oct 13, 2017

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_Mishra's avatar
    Bharat_Mishra
    Copper 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-low's avatar
      b-low
      Copper 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.

    • alexrabbi's avatar
      alexrabbi
      Brass Contributor
      Thanks Bhara_Mishra,

      I just need to do this for one user
  • vytasun's avatar
    vytasun
    Copper 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

     

    • SCROWLEY70's avatar
      SCROWLEY70
      Copper Contributor
      This was a perfect solution and did as programed. Thanks!
  • Jeffrey Suarez's avatar
    Jeffrey Suarez
    Copper 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.

Resources