Last active
August 29, 2015 14:17
-
-
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.
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
# 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