How to get email address from the emails inside an Oulook folder via PowerShell?

Viewed 2074

I have an Outlook folder, let's call it LoremIpsum, where I have more than 1000+ email drafts that I want to enumarate and do some filtering via PowerShell. I can access the folder and see the emails already, using this script:

Function HandleRemaining {
    [CmdletBinding()]
    Param()

    BEGIN {
        Clear-Host
    }

    PROCESS {
        $outlook = New-Object -ComObject outlook.application
        $mapi = $outlook.getnamespace("MAPI");

        $email = $mapi.Folders.Item(1).Folders.Item('LoremIpsum').Items(1)

        foreach ($recip in $email.Recipients) {
           $recip 
        }

        $email.To
        $email.CC
    }

    END {
    }
}

HandleRemaining

The problem is that neither $recip nor $email.To return the email address of the To or CC of that email, instead I get the person's resolved name, example:

Application           : Microsoft.Office.Interop.Outlook.ApplicationClass
Class                 : 4
Session               : Microsoft.Office.Interop.Outlook.NameSpaceClass
Parent                : System.__ComObject
Address               : /o=ExchangeLabs/ou=Exchange Administrative Group (ALPHA-NUMERIC)/cn=Recipients/cn=LONG-ALPHANUMERIC-HERE
AddressEntry          : System.__ComObject
AutoResponse          : 
DisplayType           : 0
EntryID               : <snip>
Index                 : 1
MeetingResponseStatus : 0
Name                  : John Walker
Resolved              : True
TrackingStatus        : 0
TrackingStatusTime    : 01-Jan-01 00:00:00
Type                  : 1
PropertyAccessor      : System.__ComObject
Sendable              : True

John Walker

I changed the numbers and codes to preserve privacy, but that's the return I get. So, how can I get the proper emaill address of the recipients of a given email draft?

1 Answers
Related