CatalogueMails.ps1 is used for indexing the mails to more easily filter on timestamps and senders.
This came in handy when a happy user sent me 45 attached mails with the same subjectline so the extractionprocess also throws in an indexnumber to avoid namingconflicts.
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
$scriptPath = $(split-path $myinvocation.mycommand.definition) | |
$outputPath = "$($scriptPath)\extractedMails" | |
$mails = get-childitem -Filter *.msg -Path $outputPath | |
$object = @() | |
foreach ($mail in $mails) { | |
$outlook = new-object -ComObject Outlook.application | |
try { $msg = $outlook.session.openshareditem($mail.fullname) | |
$tempObject = new-object psobject -Property @{body=$msg.body;Topic=$msg.ConversationTopic;to=$msg.to;timestamp=$msg.SentOn } | |
$object += $tempObject | |
} | |
catch { write-output "Coulnd't open $($mail.fullname)"} | |
} | |
$object |sort-object timestamp -Descending |select timestamp,Topic,to | |
$object |sort-object timestamp -Descending |select timestamp,Topic,to |export-csv -Path "$($scriptpath)\output.csv" -NoTypeInformation -Encoding UTF8 | |
write-output "Total count: $($mails.count)" |
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
$scriptPath = $(split-path $myinvocation.mycommand.definition) | |
$outputPath = "$($scriptPath)\extractedMails" | |
$inputPath = "$($scriptPath)\inputMails" | |
$mails = get-childitem -Path $inputPath -Filter *.msg | |
if ($mails -ne $null) { | |
$index = 0 | |
foreach ($mail in $mails) { | |
$outlook = new-object -ComObject Outlook.application | |
$msgFn = $mail.FullName | |
$msg = $outlook.CreateItemFromTemplate($msgFn) | |
foreach ($attachment in $msg.Attachments) { | |
if ($attachment.FileName -like "*.msg") { | |
$attFn = "$outputPath\$($index)_$($attachment.FileName)" | |
$attachment.SaveAsFile($attFn) | |
$index++ | |
} | |
else {write-output "Skipping, not a msg ($($attachment.filename))"} | |
} | |
} | |
write-output "Total count: $($mails.count). Extracted $index attachements" | |
} | |
else { write-output "No mails found $inputPath"} |
No comments:
Post a Comment