{"id":8755,"date":"2024-01-19T00:11:56","date_gmt":"2024-01-19T00:11:56","guid":{"rendered":"https:\/\/cheapwindowsvps.com\/blog\/how-to-list-and-remove-calendar-events-from-your-exchange-mailbox-using-powershell\/"},"modified":"2025-01-16T08:26:51","modified_gmt":"2025-01-16T08:26:51","slug":"how-to-list-and-remove-calendar-events-from-your-exchange-mailbox-using-powershell","status":"publish","type":"post","link":"https:\/\/cheapwindowsvps.com\/blog\/how-to-list-and-remove-calendar-events-from-your-exchange-mailbox-using-powershell\/","title":{"rendered":"How to List and Remove Calendar Events from Your Exchange Mailbox Using PowerShell"},"content":{"rendered":"<p>PowerShell enables event and meeting items accessibility in Exchange users&#8217; calendars. The following paragraphs detail how to compile a list of calendar events or erase a particular event\/appointment from the calendars of all users within an Exchange Server or Microsoft 365 organization.<\/p>\n<h2>Listing and Reading User Calendar Events on Exchange Online (Microsoft 365)<\/h2>\n<p>Initially, we&#8217;ll inspect how to compile a list of calendar events in a user&#8217;s mailbox on Exchange Online (Microsoft 365). The Microsoft Graph API is capable of retrieving data about items present in the user&#8217;s calendar. Begin by setting up a new application in Azure (<strong>Microsoft Entra ID<\/strong> -&gt; <strong>App registration -&gt; New registration<\/strong>) and bequeath it the following Microsoft Graph permissions: <code>Calendars.Read<\/code> and <code>Calendars.ReadBasic.All<\/code>.<\/p>\n<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\/\" target=\"_blank\" rel=\"nofollow noopener\">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\/\" target=\"_blank\" rel=\"nofollow noopener\">certificate-based Azure authentication in PowerShell<\/a>.<\/p>\n<p>$certThumbprint = &#8220;9CF05589A4B29BECEE6456F08A76EBC3DC2BC581&#8221;<br \/>\n$AzureAppID = &#8220;111111-2222-3333-4444-12345678&#8243;<br \/>\n$tenant=&#8221;woshub.onmicrosoft.com&#8221;<br \/>\nConnect-MgGraph -AppId $AzureAppID -CertificateThumbprint $certThumbprint -TenantId $tenant<\/p>\n<div><\/div>\n<div>If the Microsoft.Graph module is missing, install it:<\/div>\n<p><code>Install-Module Microsoft.Graph -Scope AllUsers<\/code><\/p>\n<p>To view events in a particular user\u2019s calendar for the current month:<\/p>\n<p><code>$StartDate = (Get-Date -Day 1)<br \/>\n$EndDate = (Get-Date -Day 1).Addmonths(1)<br \/>\nGet-MgUserCalendarView -UserId [email\u00a0protected] -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>The command returned the event subjects, their contents (body preview), and their start\/end times.<\/p>\n<h2>Removing Event from Exchange Calendar Using PowerShell<\/h2>\n<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>Open the PowerShell console and connect to your Exchange Online tenant (using the <a href=\"https:\/\/woshub.com\/powershell-connect-and-manage-exchange-online\/\" target=\"_blank\" rel=\"nofollow noopener\">Exchange Online PowerShell module<\/a>) or the Exchange Server host (<a href=\"https:\/\/woshub.com\/connect-exchange-microsoft-365-remote-powershell\/\" target=\"_blank\" rel=\"nofollow noopener\">remote connection to Exchange server without EMS installation<\/a>).<\/p>\n<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><code>Remove-CalendarEvents -Identity <a href=\"\/cdn-cgi\/l\/email-protection\" target=\"_blank\" rel=\"nofollow noopener\">[email\u00a0protected]<\/a> -CancelOrganizedMeetings -QueryWindowInDays 15<\/code><\/p>\n<p>Alternatively, you can delete all events starting from a specific date:<\/p>\n<p><code>Remove-CalendarEvents -Identity <a href=\"\/cdn-cgi\/l\/email-protection\" target=\"_blank\" rel=\"nofollow noopener\">[email\u00a0protected]<\/a> -CancelOrganizedMeetings -QueryStartDate 04-10-2023 -QueryWindowInDays 60<\/code><\/p>\n<p>You can use the <code>-PreviewOnly -Verbose<\/code> options to view a list of such events without deleting them.<\/p>\n<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>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\/\" target=\"_blank\" rel=\"nofollow noopener\">search and delete items in Exchange mailboxes<\/a>.<\/p>\n<p>On Exchange Server, for example, you can find calendar events with a specific subject like this:<\/p>\n<p><code>Search-Mailbox -Identity <a href=\"\/cdn-cgi\/l\/email-protection\" target=\"_blank\" rel=\"nofollow noopener\">[email\u00a0protected]<\/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>This command searches for an event in the user\u2019s mailbox and saves the results in the <em>SearchMailboxResult<\/em> folder of the <strong>report_mbx<\/strong> mailbox.<\/p>\n<p>In case you want to delete the event found, replace the last parameters with <strong>-DeleteContent<\/strong>. Here\u2019s how to delete all the events in the user\u2019s calendar:<\/p>\n<p><code>SearchMailbox -identity <a href=\"\/cdn-cgi\/l\/email-protection\" target=\"_blank\" rel=\"nofollow noopener\">[email\u00a0protected]<\/a> -SearchQuery kind:meetings -DeleteContent<\/code><\/p>\n<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><code>New-ComplianceSearch -Name DeleteITMeeting -ContentMatchQuery \"kind:meetings AND subject:weekly_it_meeting\" -ExchangeLocation all<br \/>\nStart-ComplianceSearch -identity DeleteITMeeting<br \/>\nGet-ComplianceSearch -identity DeleteITMeeting | fl<\/code><\/p>\n<p>Once the task is complete (<code>Status=Completed<\/code>), you can delete the events it has found:<\/p>\n<p><code>New-ComplianceSearchAction -SearchName DeleteITMeeting -Purge<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>PowerShell enables event and meeting items accessibility in Exchange users&#8217; calendars. The following paragraphs detail how to compile a list of calendar events or erase a particular event\/appointment from the calendars of all users within an Exchange Server or Microsoft 365 organization. Listing and Reading User Calendar Events on Exchange Online (Microsoft 365) Initially, we&#8217;ll [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":8756,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[127,128,117],"tags":[],"class_list":["post-8755","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\/8755","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=8755"}],"version-history":[{"count":2,"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/posts\/8755\/revisions"}],"predecessor-version":[{"id":10171,"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/posts\/8755\/revisions\/10171"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/media\/8756"}],"wp:attachment":[{"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/media?parent=8755"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/categories?post=8755"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cheapwindowsvps.com\/blog\/wp-json\/wp\/v2\/tags?post=8755"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}