{"id":8935,"date":"2024-01-19T16:15:17","date_gmt":"2024-01-19T16:15:17","guid":{"rendered":"https:\/\/cheapwindowsvps.com\/blog\/how-to-list-and-remove-calendar-events-from-exchange-mailbox-using-powershell\/"},"modified":"2025-01-20T10:14:34","modified_gmt":"2025-01-20T10:14:34","slug":"how-to-list-and-remove-calendar-events-from-exchange-mailbox-using-powershell","status":"publish","type":"post","link":"https:\/\/cheapwindowsvps.com\/blog\/how-to-list-and-remove-calendar-events-from-exchange-mailbox-using-powershell\/","title":{"rendered":"How to List and Remove Calendar Events from Exchange Mailbox using PowerShell"},"content":{"rendered":"<p><p>PowerShell provides the functionality to access event and meeting entries in the calendars of Exchange users. Here, we will discuss the methods of obtaining a calendar events list or deleting a particular event\/appointment from everyone&#8217;s calendars in an Exchange Server or Microsoft 365 organization.<\/p>\n<\/p>\n<p><h2>Procedure to List and View User Calendar Events in Exchange Online (Microsoft 365)<\/h2>\n<\/p>\n<p><p>In the beginning, we will understand the process to view the list of calendar events in a user&#8217;s mailbox of Exchange Online (Microsoft 365). For obtaining details about the items in the user&#8217;s calendar, we utilize the Microsoft Graph API. Commence by creating a new application in Azure (<strong>Microsoft Entra ID <\/strong>&gt; <strong>App registration&gt; New registration<\/strong>) and providing it the Microsoft Graph permissions: <code>Calendars.Read<\/code> and <code>Calendars.ReadBasic.All<\/code> respectively.<\/p>\n<\/p>\n<p><div>For more details on registering applications in Azure and granting Microsoft Graph permissions, check the post <a href=\"https:\/\/woshub.com\/access-azure-microsoft-graph-api-powershell\/\" rel=\"nofollow noopener\" target=\"_blank\">How to connect to Microsoft Graph with PowerShell<\/a>.<\/div>\n<p>Now you can use the Microsoft.Graph module to connect to the Microsoft 365 tenant. In this example, we will use <a href=\"https:\/\/woshub.com\/powershell-certificate-based-auth-exchange-azure\/\" rel=\"nofollow noopener\" target=\"_blank\">certificate-based Azure authentication in PowerShell<\/a>.<\/p>\n<p><code>$certThumbprint = \"9CF05589A4B29BECEE6456F08A76EBC3DC2BC581\"<br \/> $AzureAppID = \"111111-2222-3333-4444-12345678\"<br \/> $tenant=\"woshub.onmicrosoft.com\"<br \/> Connect-MgGraph -AppId $AzureAppID -CertificateThumbprint $certThumbprint -TenantId $tenant<\/code><\/p>\n<div><\/div>\n<\/p>\n<p><div>If the Microsoft.Graph module is missing, install it:<\/p>\n<p><code>Install-Module Microsoft.Graph -Scope AllUsers<\/code><\/p>\n<\/p>\n<\/div>\n<p><p>To view events in a particular user\u2019s calendar for the current month:<\/p>\n<\/p>\n<p><p><code>$StartDate = (Get-Date -Day 1)<\/p>\n<p><\/p>\n<p>$EndDate = (Get-Date -Day 1).Addmonths(1)<\/p>\n<p><\/p>\n<p>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<\/code><\/p>\n<\/p>\n<p><p>The command returned the event subjects, their contents (body preview), and their start\/end times.<\/p>\n<\/p>\n<p><h2>Removing Event from Exchange Calendar Using PowerShell<\/h2>\n<\/p>\n<p><p>Use the <strong>Remove-CalendarEvents<\/strong> cmdlet to cancel (delete) an event (appointment, meeting) in Exchange calendars. It works for both Exchange Online and Exchange Server 2019 organizations.<\/p>\n<\/p>\n<p><p>Open the PowerShell console and connect to your Exchange Online tenant (using the <a href=\"https:\/\/woshub.com\/powershell-connect-and-manage-exchange-online\/\" rel=\"nofollow noopener\" target=\"_blank\">Exchange Online PowerShell module<\/a>) or the Exchange Server host (<a href=\"https:\/\/woshub.com\/connect-exchange-microsoft-365-remote-powershell\/\" rel=\"nofollow noopener\" target=\"_blank\">remote connection to Exchange server without EMS installation<\/a>).<\/p>\n<\/p>\n<p><p>Removal of all upcoming events (within the next 15 days) from a user\u2019s calendar for which they are the organizer:<\/p>\n<\/p>\n<p><p><code>Remove-CalendarEvents -Identity <a href=\"\/cdn-cgi\/l\/email-protection\" rel=\"nofollow noopener\" target=\"_blank\">[email&nbsp;protected]<\/a> -CancelOrganizedMeetings -QueryWindowInDays 15<\/code><\/p>\n<\/p>\n<p><p>Alternatively, you can delete all events starting from a specific date:<\/p>\n<\/p>\n<p><p><code>Remove-CalendarEvents -Identity <a href=\"\/cdn-cgi\/l\/email-protection\" rel=\"nofollow noopener\" target=\"_blank\">[email&nbsp;protected]<\/a> -CancelOrganizedMeetings -QueryStartDate 04-10-2023 -QueryWindowInDays 60<\/code><\/p>\n<\/p>\n<p><p>You can use the <code>-PreviewOnly -Verbose<\/code> options to view a list of such events without deleting them.<\/p>\n<\/p>\n<p><p>The main disadvantage of the <em>Remove-CalendarEvents<\/em> 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\u2019s calendar of events that were created by an employee who has been fired, is off sick, or has gone on holiday.<\/p>\n<\/p>\n<p><p>If you need to delete past events, or if you are using on-premises Exchange Server 2016\/2013\/2010, you can use the <strong>Search-Mailbox<\/strong> or <strong>New-ComplianceSearch<\/strong> cmdlets to <a href=\"https:\/\/woshub.com\/search-mailbox-exchange\/\" rel=\"nofollow noopener\" target=\"_blank\">search and delete items in Exchange mailboxes<\/a>.<\/p>\n<\/p>\n<p><p>On Exchange Server, for example, you are able to locate calendar events that have a specific subject line as follows:<\/p>\n<\/p>\n<p><p><code>Search-Mailbox -Identity <a href=\"\/cdn-cgi\/l\/email-protection\" rel=\"nofollow noopener\" target=\"_blank\">[email protected]<\/a> -SearchQuery {Subject:\"Discuss: AD Schema Update\" AND Kind:meetings AND Received:01\/12\/2023..15\/01\/2024} -TargetMailbox report_mbx -TargetFolder SearchMailboxResult \u2013LogOnly -LogLevel Full<\/code><\/p>\n<\/p>\n<p><p>This command executes a search for an event within the user&#8217;s mailbox, with the search results being saved in the SearchMailboxResult folder of the report_mbx mailbox.<\/p>\n<\/p>\n<p><p>If deleting the found event is your goal, you can replace the final parameters with -DeleteContent. Here&#8217;s how to eliminate all events within the user&#8217;s calendar:<\/p>\n<\/p>\n<p><p><code>SearchMailbox -identity <a href=\"\/cdn-cgi\/l\/email-protection\" rel=\"nofollow noopener\" target=\"_blank\">[email&nbsp;protected]<\/a> -SearchQuery kind:meetings -DeleteContent<\/code><\/p>\n<\/p>\n<p><p>In Exchange Online, the SearchMailbox cmdlet is deprecated and you have to use the <strong>ComplianceSearch<\/strong> cmdlets instead. For example, to find all events with a specific subject in all mailboxes, run the commands:<\/p>\n<\/p>\n<p><p><code>New-ComplianceSearch -Name DeleteITMeeting -ContentMatchQuery \"kind:meetings AND subject:weekly_it_meeting\" -ExchangeLocation all<br \/> Start-ComplianceSearch -Identity DeleteITMeeting<br \/> Get-ComplianceSearch&nbsp;-Identity DeleteITMeeting | fl<\/code><\/p>\n<\/p>\n<p><p>Once the task is complete (<code>Status=Completed<\/code>), you can delete the events it has found:<\/p>\n<\/p>\n<p><p><code>New-ComplianceSearchAction -SearchName DeleteITMeeting -Purge<\/code><\/p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>PowerShell provides the functionality to access event and meeting entries in the calendars of Exchange users. Here, we will discuss the methods of obtaining a calendar events list or deleting a particular event\/appointment from everyone&#8217;s calendars in an Exchange Server or Microsoft 365 organization. Procedure to List and View User Calendar Events in Exchange Online [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":8936,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[127,128,117],"tags":[],"class_list":["post-8935","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-exchange","category-microsoft-365","category-powershell"],"_links":{"self":[{"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/posts\/8935","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/comments?post=8935"}],"version-history":[{"count":2,"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/posts\/8935\/revisions"}],"predecessor-version":[{"id":10339,"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/posts\/8935\/revisions\/10339"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/media\/8936"}],"wp:attachment":[{"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/media?parent=8935"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/categories?post=8935"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/tags?post=8935"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}