Skip to content

Instantly share code, notes, and snippets.

@bill-long
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bill-long/c8f41b2f0433429c9539 to your computer and use it in GitHub Desktop.
Save bill-long/c8f41b2f0433429c9539 to your computer and use it in GitHub Desktop.
Scours an ldifde tombstone dump for all objects with MailboxExport in the name, and outputs basic data for easy importing into Excel.
# Find-MailboxExportTombstones
$file = 'C:\someldiffile.txt'
Add-Type @"
using System;
public class Tombstone {
public DateTime WhenCreated;
public DateTime WhenChanged;
public Guid ObjectGuid;
public string Dn;
}
"@
$latestDN = ""
$latestCreateTime = [DateTime]::MinValue
$latestChanged = [DateTime]::MinValue
$format = "yyyyMMddHHmmss"
$tombstones = @()
$reader = New-Object System.IO.StreamReader($file)
while ($null -ne ($buffer = $reader.ReadLine()))
{
if ($buffer.StartsWith("dn:"))
{
$latestDN = $buffer
}
elseif ($buffer.StartsWith("whenCreated:"))
{
$latestCreateTime = [DateTime]::ParseExact($buffer.Substring(13, 14), $format, [CultureInfo]::InvariantCulture)
}
elseif ($buffer.StartsWith("whenChanged:"))
{
$latestChanged = [DateTime]::ParseExact($buffer.Substring(13, 14), $format, [CultureInfo]::InvariantCulture)
}
elseif ($buffer.StartsWith("objectGUID:: "))
{
if ($latestDN.Contains("MailboxExport"))
{
$guid = New-Object Guid(,[Convert]::FromBase64String($buffer.Substring(13)))
$thisTombstone = New-Object Tombstone
$thisTombstone.Dn = $latestDN
$thisTombstone.WhenCreated = $latestCreateTime
$thisTombstone.WhenChanged = $latestChanged
$thisTombstone.ObjectGuid = $guid
$tombstones += $thisTombstone
}
}
}
$reader.Close()
$tombstones | Sort WhenChanged -Descending | ft WhenChanged,WhenCreated,ObjectGuid,Dn -AutoSize | Out-String -Width 4096 | Out-File $home\desktop\MailboxExportTombstones.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment