Outlook: Viewing mail items

Continuing our perambulation around Outlook when used with multiple hotmail accounts its time to look at the other folders and the mail items they contain. This post will show how to view the mail items and a future post will show how to delete items from a specific folder.

Viewing mail items cam be performed with the following function

function get-mailitem {            
param (            
 [parameter(Mandatory=$true)]            
 [string]$mailfolder,            
              
 [switch]$all            
)            
$outlook = New-Object -ComObject Outlook.Application            
            
$folders | where {$_.Path -like "*$mailfolder"} |            
foreach {            
  $targetfolder = $outlook.Session.GetFolderFromID($_.EntryID, $_.StoreID)            
              
  if ($all){            
   $targetfolder.Items             
  }            
  else {            
   $targetfolder.Items | sort  SentOn -desc | select SenderEmailAddress, Subject, SentOn            
  }            
}            
}

The function takes a mandatory string to identify the mail folder and we use the GetFolderFromID method to access the folder. If the –all switch is used we get a dump of the full object for each mail item otherwise a summary consisting of the sender’s address, date sent and subject is output.

If the –all switch is used we can use the PowerShell pipeline to perform further processing e.g.

get-mailitem –mailfolder Baen –all | where {$_.SentOn –lt [datetime]”1 January 2007”}

About these ads
This entry was posted in Office 2010, Outlook, PowerShell V2, Windows 7. Bookmark the permalink.

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