Powershell - DEALING WITH EMAILS

DEALING WITH EMAILS


e-mail object properties:
Name                              MemberType Definition
----                              ---------- ----------
AddBusinessCard                   Method     void AddBusinessCard (ContactItem)
ClearConversationIndex            Method     void ClearConversationIndex ()
ClearTaskFlag                     Method     void ClearTaskFlag ()
Close                             Method     void Close (OlInspectorClose)
Copy                              Method     IDispatch Copy ()
Delete                            Method     void Delete ()
Display                           Method     void Display (Variant)
Forward                           Method     MailItem Forward ()
GetConversation                   Method     _Conversation GetConversation ()
MarkAsTask                        Method     void MarkAsTask (OlMarkInterval)
Move                              Method     IDispatch Move (MAPIFolder)
PrintOut                          Method     void PrintOut ()
Reply                             Method     MailItem Reply ()
ReplyAll                          Method     MailItem ReplyAll ()
Save                              Method     void Save ()
SaveAs                            Method     void SaveAs (string, Variant)
Send                              Method     void Send ()
ShowCategoriesDialog              Method     void ShowCategoriesDialog ()
Actions                           Property   Actions Actions () {get}
AlternateRecipientAllowed         Property   bool AlternateRecipientAllowed () {get} {set}
Application                       Property   _Application Application () {get}
Attachments                       Property   Attachments Attachments () {get}
AutoForwarded                     Property   bool AutoForwarded () {get} {set}
AutoResolvedWinner                Property   bool AutoResolvedWinner () {get}
BCC                               Property   string BCC () {get} {set}
BillingInformation                Property   string BillingInformation () {get} {set}
Body                              Property   string Body () {get} {set}
BodyFormat                        Property   OlBodyFormat BodyFormat () {get} {set}
Categories                        Property   string Categories () {get} {set}
CC                                Property   string CC () {get} {set}
Class                             Property   OlObjectClass Class () {get}
Companies                         Property   string Companies () {get} {set}
Conflicts                         Property   Conflicts Conflicts () {get}
ConversationID                    Property   string ConversationID () {get}
ConversationIndex                 Property   string ConversationIndex () {get}
ConversationTopic                 Property   string ConversationTopic () {get}
CreationTime                      Property   Date CreationTime () {get}
DeferredDeliveryTime              Property   Date DeferredDeliveryTime () {get} {set}
DeleteAfterSubmit                 Property   bool DeleteAfterSubmit () {get} {set}
DownloadState                     Property   OlDownloadState DownloadState () {get}
EnableSharedAttachments           Property   bool EnableSharedAttachments () {get} {set}
EntryID                           Property   string EntryID () {get}
ExpiryTime                        Property   Date ExpiryTime () {get} {set}
FlagDueBy                         Property   Date FlagDueBy () {get} {set}
FlagIcon                          Property   OlFlagIcon FlagIcon () {get} {set}
FlagRequest                       Property   string FlagRequest () {get} {set}
FlagStatus                        Property   OlFlagStatus FlagStatus () {get} {set}
FormDescription                   Property   FormDescription FormDescription () {get}
GetInspector                      Property   _Inspector GetInspector () {get}
HasCoverSheet                     Property   bool HasCoverSheet () {get} {set}
HTMLBody                          Property   string HTMLBody () {get} {set}
Importance                        Property   OlImportance Importance () {get} {set}
InternetCodepage                  Property   int InternetCodepage () {get} {set}
IsConflict                        Property   bool IsConflict () {get}
IsIPFax                           Property   bool IsIPFax () {get} {set}
IsMarkedAsTask                    Property   bool IsMarkedAsTask () {get}
ItemProperties                    Property   ItemProperties ItemProperties () {get}
LastModificationTime              Property   Date LastModificationTime () {get}
Links                             Property   Links Links () {get}
MAPIOBJECT                        Property   IUnknown MAPIOBJECT () {get}
MarkForDownload                   Property   OlRemoteStatus MarkForDownload () {get} {set}
MessageClass                      Property   string MessageClass () {get} {set}
Mileage                           Property   string Mileage () {get} {set}
NoAging                           Property   bool NoAging () {get} {set}
OriginatorDeliveryReportRequested Property   bool OriginatorDeliveryReportRequested () {get} {set}
OutlookInternalVersion            Property   int OutlookInternalVersion () {get}
OutlookVersion                    Property   string OutlookVersion () {get}
Parent                            Property   IDispatch Parent () {get}
Permission                        Property   OlPermission Permission () {get} {set}
PermissionService                 Property   OlPermissionService PermissionService () {get} {set}
PermissionTemplateGuid            Property   string PermissionTemplateGuid () {get} {set}
PropertyAccessor                  Property   PropertyAccessor PropertyAccessor () {get}
ReadReceiptRequested              Property   bool ReadReceiptRequested () {get} {set}
ReceivedByEntryID                 Property   string ReceivedByEntryID () {get}
ReceivedByName                    Property   string ReceivedByName () {get}
ReceivedOnBehalfOfEntryID         Property   string ReceivedOnBehalfOfEntryID () {get}
ReceivedOnBehalfOfName            Property   string ReceivedOnBehalfOfName () {get}
ReceivedTime                      Property   Date ReceivedTime () {get}
RecipientReassignmentProhibited   Property   bool RecipientReassignmentProhibited () {get} {set}
Recipients                        Property   Recipients Recipients () {get}
ReminderOverrideDefault           Property   bool ReminderOverrideDefault () {get} {set}
ReminderPlaySound                 Property   bool ReminderPlaySound () {get} {set}
ReminderSet                       Property   bool ReminderSet () {get} {set}
ReminderSoundFile                 Property   string ReminderSoundFile () {get} {set}
ReminderTime                      Property   Date ReminderTime () {get} {set}
RemoteStatus                      Property   OlRemoteStatus RemoteStatus () {get} {set}
ReplyRecipientNames               Property   string ReplyRecipientNames () {get}
ReplyRecipients                   Property   Recipients ReplyRecipients () {get}
RetentionExpirationDate           Property   Date RetentionExpirationDate () {get}
RetentionPolicyName               Property   string RetentionPolicyName () {get}
RTFBody                           Property   Variant RTFBody () {get} {set}
Saved                             Property   bool Saved () {get}
SaveSentMessageFolder             Property   MAPIFolder SaveSentMessageFolder () {get} {set by ref}
Sender                            Property   AddressEntry Sender () {get} {set}
SenderEmailAddress                Property   string SenderEmailAddress () {get}
SenderEmailType                   Property   string SenderEmailType () {get}
SenderName                        Property   string SenderName () {get}
SendUsingAccount                  Property   Account SendUsingAccount () {get} {set}
Sensitivity                       Property   OlSensitivity Sensitivity () {get} {set}
Sent                              Property   bool Sent () {get}
SentOn                            Property   Date SentOn () {get}
SentOnBehalfOfName                Property   string SentOnBehalfOfName () {get} {set}
Session                           Property   _NameSpace Session () {get}
Size                              Property   int Size () {get}
Subject                           Property   string Subject () {get} {set}
Submitted                         Property   bool Submitted () {get}
TaskCompletedDate                 Property   Date TaskCompletedDate () {get} {set}
TaskDueDate                       Property   Date TaskDueDate () {get} {set}
TaskStartDate                     Property   Date TaskStartDate () {get} {set}
TaskSubject                       Property   string TaskSubject () {get} {set}
To                                Property   string To () {get} {set}
ToDoTaskOrdinal                   Property   Date ToDoTaskOrdinal () {get} {set}
UnRead                            Property   bool UnRead () {get} {set}
UserProperties                    Property   UserProperties UserProperties () {get}
VotingOptions                     Property   string VotingOptions () {get} {set}
VotingResponse                    Property   string VotingResponse () {get} {set}



GRAB THE SPECIFIC PROPERTIES FROM THE MESSAGES IN THE INBOX:


#### CONECTION TO MAILBOX ####
$olFolderInbox = 6
$outlook = new-object -com outlook.application;
$mapi = $outlook.GetNameSpace("MAPI");
$inbox = $mapi.GetDefaultFolder($olFolderInbox)
####  GET INFORMATION AND DUMP TO A CSV FILE. ###
$inbox.items|Select SenderEmailAddress,to,subject|Export-Csv C:\EmailInfoDump.csv -NoTypeInformation


READ THROUGH A PST/OST


#### PATH TO PST/OST ####
[string]$pstPath = "C:\backup.pst"
### IF OUTLOOK IS NOT RUNNING, LAUNCH A HIDDEN INSTANCE. ###
$oProc = ( Get-Process | where { $_.Name -eq "OUTLOOK" } )
if ( $oProc -eq $null ) { Start-Process outlook -WindowStyle Hidden; Start-Sleep -Seconds 5 }
$outlook = New-Object -ComObject Outlook.Application
$namespace = $outlook.GetNamespace("MAPI")
$namespace.AddStoreEx($pstPath, "olStoreDefault")
$pstStore = ( $nameSpace.Stores | where { $_.FilePath -eq $pstPath } )
$pstRootFolder = $pstStore.GetRootFolder()
$inboxFolder = $pstRootFolder.Folders|? { $_.Name -eq 'Inbox' }
####  GET INFORMATION AND DUMP TO A CSV FILE. ###
$inboxFolder.Items|Select SenderEmailAddress,to,subject|Export-Csv C:\EmailInfoDump.csv -NoTypeInformation



EXAMPLE OF OUTPUT


SenderEmailAddress                   To                             Subject
------------------                   --                             -------
BBunny@ACME.com                   Bugs Bunny                  nedd a carrot
DDuck@ACME.com                    Daffy Duck                  where is that silly rabbit!
TDEVIL@ACME.com                   Taz Devil                   i can't stop spinning