Search Email AND output TAB delimited

I was trying to help someone who wanted a TAB delimited output file in PowerShell.
 
After some searching around and some help from the boards, I came up with this;
 
<———— Start POSH —————————————————————–>
 
$info = New-Object -ComObject Outlook.Application
$objNamespace = $info.GetNamespace("MAPI")
$objFolder = $objNamespace.GetDefaultFolder(6).Folders.Item("Reporting")
$colItems = $objFolder.Items
foreach ($item in $colItems) {
 If ($item.SenderEmailAddress -eq "Bill.Smith@myob.com") {
 Write-Host "$($item.SenderEmailAddress) `t $($item.SentOn) `t $($item.Subject)"
                   }
        }
 
<———–End Script ———————————————————————->
 
Or you could output to a file by removing the Write-Host and adding | Add-Content $path
 
<—————– Start POSH ————————————————————–> 
$path = "c:tempemail.txt"
$info = New-Object -ComObject Outlook.Application
$objNamespace = $info.GetNamespace("MAPI")
$objFolder = $objNamespace.GetDefaultFolder(6).Folders.Item("Merchant Reporting")
$colItems = $objFolder.Items
foreach ($item in $colItems) {
 If ($item.SenderEmailAddress -eq "Bill.Smith@myob.com") {
("$($item.SenderEmailAddress) `t $($item.SentOn) `t $($item.Subject)")| Add-Content $path
                   }
        }
 
< ————– End Script —————————————————————————->
What does it do?
 
Searches the In box for a sub folder and then for a sender.
writes them out to the screen or a file in a tab delimited format
Includes Senders name, Date/time sent and subject.
Its the `t that adds the tabs. `n adds a new line.  ‘r adds a line feed  
 
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s