Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ssstonebraker/34d65d21c9f80835d7d0c028a64f2b2e to your computer and use it in GitHub Desktop.
Save ssstonebraker/34d65d21c9f80835d7d0c028a64f2b2e to your computer and use it in GitHub Desktop.
Search exported ediscovery msg files from exchange compliance center for a string
# ediscovery_search_exported_msg_files.ps1
# Search through exported .msg files from content search (exchange compliance center) and return a spreadsheet of email addresses and matched URLs
# Kill outlook
cmd.exe /c "taskkill /F /IM outlook.exe /T 2> nul"
$scriptPath = $(split-path $myinvocation.mycommand.definition)
$inputPath = "$($scriptPath)\inputMails"
# Find all .msg files recursively
$mails = get-childitem -recurse -Filter *.msg -Path $inputPath
$object = @()
foreach ($mail in $mails) {
try {
$outlook = new-object -ComObject Outlook.application
$msg = $outlook.session.openshareditem($mail.fullname)
# match first URL found
$URLString = ((Select-String '(http[s]?|[s]?ftp[s]?)(:\/\/)([^\s,]+)' -Input $msg.Body).Matches.Value)
write-output "Found String: $URLString"
#match email address found in folder structure
$emailaddress = ((Select-String '(\w+@\w+\.com)' -Input $mail.fullname).Matches.Value)
write-output "$emailaddress"
# Uncomment if you want full body and first last name
#$tempObject = new-object psobject -Property @{body=$URLString;Topic=$msg.ConversationTopic;to=$msg.to;fullname=$mail.FullName;timestamp=$msg.SentOn }
$tempObject = new-object psobject -Property @{body=$URLString;to=$emailaddress;timestamp=$msg.SentOn }
$object += $tempObject
}
catch { write-output "Coulnd't open $($mail.fullname)"}
}
$object |sort-object timestamp -Descending |select timestamp,body,to
$object |sort-object timestamp -Descending |select timestamp,body,to |export-csv -Path "$($scriptpath)\output.csv" -NoTypeInformation -Encoding UTF8
write-output "Total count: $($mails.count)"
cmd.exe /c "taskkill /F /IM outlook.exe /T 2> nul"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment