This is the code I am using to parse my emails. If they match a specific date, I want to add them to a list of other emails, then make that into a flat file:
outfile = "C:\Temp\emails.csv"
$olFolderInbox = 6
$ol = new-object -comobject "Outlook.Application"
$mapi = $ol.getnamespace("mapi")
$inbox = $mapi.GetDefaultFolder($olFolderInbox)
$msgs = $inbox.Folders.Item("root")
$list1 = @()
foreach($message in ($msgs.items))
{
if($message.ReceivedTime -gt $(get-date).adddays(-14))
{
$list1 += "$($message.Subject);$($message.ReceivedTime);$($message.Body.Replace("`n",", "))"
}
}
if(Test-Path $outfile)
{
Remove-Item $outfile
Add-Content $outfile $list1
}
else
{
Add-Content $outfile $list1
}
The problem I run into is that the replace statement on $message.Body.Replace("`n",", ")
doesn't actually remove newlines, and the file doesn't get created appropriately. Is there a way to confirm that the entire contents of the body portion become a single line?
I have confirmed that the $message.body
object is a string, so I'm not certain why this is not working.
no ? – Loïc MICHEL Jan 29 '13 at 22:05