You can use Exchange Web Services to get the data from the actual mailbox. There's one important piece of configuration needed, and that is the role assignment for impersonation. This can be easily created with:
New-ManagementRoleAssignment -User <Administrator> -Role ApplicationImpersonation
Then the code below can be used. You'll have to replace <AdministratorEmailAddress> with the email address belonging to the admin that has been granted the impersonation role.
<TargetEmailAddress> is the mailbox for which you want to obtain the statistics. The folder name was specified as 'Inbox' but this can be changed as well in the $seachFilter, right near the end. Also, the number of messages retrieved is set for
100, but this can be easily changed in the 3rd line from the bottom.
Add-Type -Path "C:\Program Files\Microsoft\Exchange\Web Services\1.2\Microsoft.Exchange.WebServices.dll"
$service = New-Object Microsoft.Exchange.WebServices.Data.ExchangeService([Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Exchange2010_SP1)
$service.UseDefaultCredentials=$true
$service.AutodiscoverUrl("<AdministratorEmailAddress>",{$true})
$service.ImpersonatedUserId = New-Object Microsoft.Exchange.WebServices.Data.ImpersonatedUserId([Microsoft.Exchange.WebServices.Data.ConnectingIdType]::SmtpAddress, "<TargetEmailAddress>")
$MailboxRoot = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service, [Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::MsgFolderRoot)
$View = New-Object Microsoft.Exchange.WebServices.Data.FolderView(2)
$View.PropertySet = [Microsoft.Exchange.WebServices.Data.BasePropertySet]::IdOnly
$SearchFilter = New-Object Microsoft.Exchange.WebServices.Data.SearchFilter+IsEqualTo([Microsoft.Exchange.WebServices.Data.FolderSchema]::DisplayName, 'Inbox')
$folder=[Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$MailboxRoot.FindFolders($SearchFilter, $View).Id)
$psPropset = new-object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)
$messages=$folder.FindItems(100)
[void]$service.LoadPropertiesForItems($messages,$psPropset)
$messages.Items | Select-Object DateTimeReceived, Sender, ToRecipients, ConversationTopic
The code was derived from
this blog post.