MVP Systems Software  
email us now

Automating Outlook Tasks

Expand / Collapse
 

Automating Outlook Tasks


JAMS has the ability to automate Outlook tasks such as saving attachments or exporting email information.

While Outlook profile settings and Exchange security settings can complicate these tasks, Outlook provides COM objects for automation within Powershell.

The following examples parse the Test folder within the Outlook Inbox.


Example #1. Exporting the Sender email addresses from an Outlook folder:

$olFolderInbox = 6
$ol = new-object -comobject "Outlook.Application"
$mapi = $ol.getnamespace("mapi")
$inbox = $mapi.GetDefaultFolder($olFolderInbox)
$msgs = $inbox.Folders.Item("Test")
$msgs.items | Select-Object SenderName, SenderEmailAddress -unique | export-Csv c:\emails.csv -noTypeInformation


Example #2. Saving the email attachments from an Outlook folder:


$olFolderInbox = 6
$ol = new-object -comobject "Outlook.Application"
$mapi = $ol.getnamespace("mapi")
$inbox = $mapi.GetDefaultFolder($olFolderInbox)
$msgs = $inbox.Folders.Item("Test")

foreach ($group in $msgs.items |% {$_.attachments} | group filename)

{
    trap {
        Write-Host There was a problem saving $fName
        continue
        }
$fName = "C:\TEMP\$($group.Name)"
$group.Group[0].saveasfile($fName)
    if ($?) {Write-Host $fName was saved succesfuly.}
}



Rate this Article:

Add Your Comments


Name: *
Email Address:
Web Address:
   
  
 
 
   
Verification Code:
*
 

Details
Last Modified:Wednesday, September 22, 2010

Last Modified By: DanielS

Type: HOWTO

Rated 5 stars based on 1 vote

Article has been viewed 726 times.

Options