Windows OS Hub
  • Windows
    • Windows 11
    • Windows Server 2022
    • Windows 10
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
  • PowerShell
  • Linux
  • Home
  • About

Windows OS Hub

  • Windows
    • Windows 11
    • Windows Server 2022
    • Windows 10
    • Windows Server 2019
    • Windows Server 2016
  • Microsoft
    • Active Directory (AD DS)
    • Group Policies (GPOs)
    • Exchange Server
    • Azure and Microsoft 365
    • Microsoft Office
  • Virtualization
    • VMware
    • Hyper-V
  • PowerShell
  • Linux

 Windows OS Hub / Exchange / List and Remove Calendar Events from Exchange Mailbox with PowerShell

March 15, 2024 Azure and Microsoft 365ExchangePowerShell

List and Remove Calendar Events from Exchange Mailbox with PowerShell

PowerShell allows you to access event and meeting items in Exchange users’ calendars. In this post, we will look at how to get a list of calendar events or remove a specific event/appointment from the calendars of all users on an Exchange Server or Microsoft 365 organization.

Contents:
  • How to List and Read User Calendar Events in Exchange Online (Microsoft 365)
  • Removing Event from Exchange Calendar Using PowerShell

How to List and Read User Calendar Events in Exchange Online (Microsoft 365)

First, let’s look at how to get a list of calendar events in an Exchange Online (Microsoft 365) user’s mailbox. The Microsoft Graph API can retrieve information about items in the user’s calendar. Start by registering a new application in Azure (Microsoft Entra ID -> App registration -> New registration) and granting it the following Microsoft Graph permissions: Calendars.Read and Calendars.ReadBasic.All.

Grant Microsoft Graph API permissions in Azure

For more details on registering applications in Azure and granting Microsoft Graph permissions, check the post How to connect to Microsoft Graph with PowerShell.

Now you can use the Microsoft.Graph module to connect to the Microsoft 365 tenant. In this example, we will use certificate-based Azure authentication in PowerShell.

$certThumbprint = "9CF05589A4B29BECEE6456F08A76EBC3DC2BC581"
$AzureAppID = "111111-2222-3333-4444-12345678"
$tenant="woshub.onmicrosoft.com"
Connect-MgGraph -AppId $AzureAppID -CertificateThumbprint $certThumbprint -TenantId $tenant

If the Microsoft.Graph module is missing, install it:

Install-Module Microsoft.Graph -Scope AllUsers

To view events in a particular user’s calendar for the current month:

$StartDate = (Get-Date -Day 1)
$EndDate = (Get-Date -Day 1).Addmonths(1)
Get-MgUserCalendarView -UserId [email protected] -CalendarId "Calendar" -StartDateTime $StartDate -EndDateTime $EndDate | Select-Object -Property @{Name='EventStart';Expression={ $_.Start.DateTime}},@{Name='EventEnd';Expression={ $_.End.DateTime}},Subject, BodyPreview

PowerShell: Get all calendar events for a specific Exchange user

The command returned the event subjects, their contents (body preview), and their start/end times.

Removing Event from Exchange Calendar Using PowerShell

Use the Remove-CalendarEvents cmdlet to cancel (delete) an event (appointment, meeting) in Exchange calendars. It works for both Exchange Online and Exchange Server 2019 organizations.

Open the PowerShell console and connect to your Exchange Online tenant (using the Exchange Online PowerShell module) or the Exchange Server host.

Remove of all upcoming events (within the next 15 days) from a user’s calendar for which they are the organizer:

Remove-CalendarEvents -Identity [email protected] -CancelOrganizedMeetings -QueryWindowInDays 15

Or, you can delete all events starting from a specific date:

Remove-CalendarEvents -Identity [email protected] -CancelOrganizedMeetings -QueryStartDate 04-10-2023 -QueryWindowInDays 60

You can use the -PreviewOnly -Verbose options to view a list of such events without deleting them.

The main disadvantage of the Remove-CalendarEvents cmdlet is that it can only remove upcoming calendar events and does not allow you to select events by subject, organizer, content, or any other property. The most common use of Remove-CalendarEvents is to quickly clear a user’s calendar of events that were created by an employee who has been fired, is off sick, or has gone on holiday.

If you need to delete past events, or if you are using on-premises Exchange Server 2016/2013/2010, you can use the Search-Mailbox or New-ComplianceSearch cmdlets to search and delete items in Exchange mailboxes.

On Exchange Server, for example, you can find calendar events with a specific subject like this:

Search-Mailbox -Identity [email protected] -SearchQuery {Subject:"Discuss: AD Schema Update" AND Kind:meetings AND Received:01/12/2023..15/01/2024} -TargetMailbox report_mbx -TargetFolder SearchMailboxResult –LogOnly -LogLevel Full

This command searches for an event in the user’s mailbox and saves the results in the SearchMailboxResult folder of the report_mbx mailbox.

In case you want to delete the event found, replace the last parameters with -DeleteContent. Here’s how to delete all the events in the user’s calendar:

SearchMailbox -identity [email protected] -SearchQuery kind:meetings -DeleteContent

In Exchange Online, the SearchMailbox cmdlet is deprecated and you have to use the ComplianceSearch cmdlets instead. For example, to find all events with a specific subject in all mailboxes, run the commands:

New-ComplianceSearch -Name DeleteITMeeting -ContentMatchQuery "kind:meetings AND subject:weekly_it_meeting" -ExchangeLocation all
Start-ComplianceSearch -identity DeleteITMeeting
Get-ComplianceSearc -identity DeleteITMeeting | fl

Once the task is complete (Status=Completed), you can delete the events it has found:

New-ComplianceSearchAction -SearchName DeleteITMeeting -Purge

0 comment
2
Facebook Twitter Google + Pinterest
previous post
How to Create a Virtual Machine on VMWare ESXi
next post
Error: The Specified Domain Doesn’t Exist or Couldn’t Be Contacted

Related Reading

View Windows Update History with PowerShell (CMD)

April 30, 2025

Uninstalling Windows Updates via CMD/PowerShell

April 18, 2025

Allowing Ping (ICMP Echo) Responses in Windows Firewall

April 15, 2025

How to Pause (Delay) Update Installation on Windows...

April 11, 2025

How to Write Logs to the Windows Event...

March 3, 2025

Leave a Comment Cancel Reply

join us telegram channel https://t.me/woshub
Join WindowsHub Telegram channel to get the latest updates!

Categories

  • Active Directory
  • Group Policies
  • Exchange Server
  • Microsoft 365
  • Azure
  • Windows 11
  • Windows 10
  • Windows Server 2022
  • Windows Server 2019
  • Windows Server 2016
  • PowerShell
  • VMware
  • Hyper-V
  • Linux
  • MS Office

Recent Posts

  • Map a Network Drive over SSH (SSHFS) in Windows

    May 13, 2025
  • Configure NTP Time Source for Active Directory Domain

    May 6, 2025
  • Cannot Install Network Adapter Drivers on Windows Server

    April 29, 2025
  • Change BIOS from Legacy to UEFI without Reinstalling Windows

    April 21, 2025
  • How to Prefer IPv4 over IPv6 in Windows Networks

    April 9, 2025
  • Load Drivers from WinPE or Recovery CMD

    March 26, 2025
  • How to Block Common (Weak) Passwords in Active Directory

    March 25, 2025
  • Fix: The referenced assembly could not be found error (0x80073701) on Windows

    March 17, 2025
  • Exclude a Specific User or Computer from Group Policy

    March 12, 2025
  • AD Domain Join: Computer Account Re-use Blocked

    March 11, 2025

Follow us

  • Facebook
  • Twitter
  • Telegram
Popular Posts
  • Automatic Outlook User Profile Configuration with ZeroConfigExchange
  • Configuring Password Policy in Microsoft Entra ID
  • Prevent Users from Creating New Groups in Microsoft 365 (Teams/Outlook)
  • Sending an E-mail to a Microsoft Teams Channel
  • Fix: “Something Went Wrong” Error When Installing Teams
  • Send Emails with Microsoft Graph API and PowerShell
  • How to Export MS Teams Chat History with PowerShell
Footer Logo

@2014 - 2024 - Windows OS Hub. All about operating systems for sysadmins


Back To Top