Last active
April 29, 2021 21:55
-
-
Save bill-long/e2d307cb89f2642bddff72d75e101682 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.SYNOPSIS | |
Finds a mailbox item using a partial EntryId and a message class. | |
.DESCRIPTION | |
Corrupted items may have only a few properties and an EntryId that | |
cannot be opened in MFCMapi. This often surfaces as a reminder that | |
repeatedly shows up while the appointment for that reminder cannot | |
be found. | |
When other approaches fail, you can find the corrupted | |
appointment by finding the reminder in MFCMapi and copying the last | |
4 bytes (8 characters) of the PR_ENTRYID value. Use that value | |
with this script, and this script will report the folder that | |
contains the appointment in question. | |
At that point, you can use MFCMapi to go to that folder, sort by | |
Subject, and then delete the corrupted appointment. After the | |
appointment is deleted, the reminder is gone. | |
Note that it is usually necessary to disable the calendar version | |
store to delete a corrupted appointment. Run: | |
Set-Mailbox -CalendarVersionStoreDisabled $true | |
This can take up to two hours to take effect. After that, the | |
appointment can be deleted. | |
.EXAMPLE | |
PS C:\> .\Find-PartialEntryId -Mailbox "Smith, Joe" -PartialEntryId "4C4DFA7A" | |
Finds an appointment in the "Smith, Joe" mailbox with a matching EntryId. | |
.EXAMPLE | |
PS C:\> .\Find-PartialEntryId -Mailbox "Smith, Joe" -PartialEntryId "4C4DFA7A" -MessageClass "IPM.Note" | |
Finds an IPM.Note item in the "Smith, Joe" mailbox with a matching EntryId. | |
#> | |
[CmdletBinding()] | |
param ( | |
[Parameter(Mandatory = $true)] | |
[string] | |
$Mailbox, | |
[Parameter(Mandatory = $true)] | |
[string] | |
$PartialEntryId, | |
[Parameter()] | |
[string] | |
$MessageClass = "IPM.Appointment" | |
) | |
. $exscripts\ManagedStoreDiagnosticFunctions.ps1 | |
$mb = Get-Mailbox $Mailbox | |
$mbTableResult = Get-StoreQuery -Database "$($mb.Database.ToString())" -Query "SELECT MailboxNumber FROM Mailbox WHERE MailboxGuid = '$($mb.ExchangeGuid.ToString())'" | |
Write-Host "Found mailbox $($mb.DisplayName) with mailbox number $($mbTableResult.MailboxNumber)." | |
$mailboxNumber = $mbTableResult.MailboxNumber | |
$messageTableResult = @(Get-StoreQuery -Database "$($mb.Database.ToString())" -Query "SELECT FolderId,MessageId FROM Message WHERE MailboxNumber = $mailboxNumber AND MessageClass = `"$MessageClass`"" -Unlimited | Where-Object { | |
$_.MessageId.ToString() -like "*$($PartialEntryId)*" | |
}) | |
Write-Host "Found $($messageTableResult.Length) message table results with matching EntryId." | |
$folderTableResults = Get-StoreQuery -Database "$($mb.Database.ToString())" -Query "SELECT FolderId,ParentFolderId,DisplayName FROM Folder WHERE MailboxNumber = $mailboxNumber" -Unlimited | |
$folderPath = "" | |
$currentId = $messageTableResult.FolderId | |
$matchingFolder = $null | |
do { | |
$matchingFolder = @($folderTableResults | Where-Object { $_.FolderId -eq $currentId }) | |
if ($matchingFolder.Length -gt 0) { | |
$folderPath = $matchingFolder.DisplayName + "\" + $folderPath | |
$currentId = $matchingFolder.ParentFolderId | |
} | |
} while ($matchingFolder.Length) | |
Write-Host "Item was found in folder: $folderPath" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment