79620581

Date: 2025-05-14 00:43:30
Score: 0.5
Natty:
Report link
# Connect Outlook, MAPI Namespace
$outlookCom = New-Object -comObject Outlook.Application
$Namespace = $outlookCom.GetNamespace('MAPI')

# Select 'Inbox' folder for default account
$InboxFolder = $Namespace.GetDefaultFolder([Microsoft.Office.Interop.Outlook.OlDefaultFolders]::olFolderInbox)


#Alternate - Select Email Account, Select Folder
#Using 'Inbox' folder as example
$thisAccount = $Namespace.Folders | Where-Object {$_.Name -match '^MyEmailAccount'}
$targetFolder = $thisAccount.Folders | Where-Object {$_.Name -match '^inbox'}

#Get actual mail items from the target folder + view the available methods+properties
$targetFolder.Items() | Select-Object -First 1 | Get-Member

You are looking for "the body and receivers" -
There are a couple ways to get that. You'll need to test and see what gives you the data you want:

Name                              MemberType Definition
----                              ---------- ----------
Body                              Property   string Body () {get} {set}
CC                                Property   string CC () {get} {set}
ReceivedByName                    Property   string ReceivedByName () {get}
Recipients                        Property   Recipients Recipients () {get}
To                                Property   string To () {get} {set}

Note - some of these are returned as another ComObject, not a string, and require more effort to view and query. These need to be separately accessed and expanded - see example:

# View multiple properties, including 'Recipients' from the first item found
$targetFolder.Items()[1] | Select-Object -Property SentOn,Subject,Recipients | Format-List

  SentOn     : 5/13/2025 1:23:45 PM
  Subject    : Important Test Email
  Recipients : System.__ComObject


# Trying to 'expand' 'Recipients' property returned as a ComObject
$targetFolder.Items()[1] | Select-Object -ExpandProperty Recipients

  Application : Microsoft.Office.Interop.Outlook.ApplicationClass
  Class       : 17
  Session     : Microsoft.Office.Interop.Outlook.NameSpaceClass
  Parent      : System.__ComObject
  Count       : 1

# Accessing 'Recipients' by dot
$targetFolder.Items()[1].Recipients

  Application           : Microsoft.Office.Interop.Outlook.ApplicationClass
  Class                 : 4
  Session               : Microsoft.Office.Interop.Outlook.NameSpaceClass
  Parent                : System.__ComObject
  Address               : AddressGoesHere
  AddressEntry          : System.__ComObject
  AutoResponse          :
  DisplayType           : 1
  EntryID               : IDGoesHere
  Index                 : 1
  MeetingResponseStatus : 0
  Name                  : ThisIsTheRecipientsList

Sources (I've had to reference the MSDN one for years):

Reasons:
  • Probably link only (1):
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: user2522669