$yesterday=(get-date).adddays(-1) $tomorrow=(get-date).adddays(+1) $output=[pscustomobject]@{ DisplayName="" sent = 0 recieved = 0 RecipientTypeDetails ="" PrimarySmtpAddress="" } $mailboxes=get-mailbox -ResultSize unlimited foreach ($mailbox in $mailboxes) { $output.DisplayName=$mailbox.DisplayName $output.DisplayName $output.PrimarySmtpAddress=$mailbox.PrimarySmtpAddress $output.PrimarySmtpAddress $output.RecipientTypeDetails=$mailbox.RecipientTypeDetails $output.RecipientTypeDetails $output.sent=(Get-MessageTrackingLog -Start $yesterday -End $tomorrow -Sender (get-mailbox $mailbox).primarysmtpaddress -ResultSize unlimited).count $output.sent $output.recieved=(Get-MessageTrackingLog -Start $yesterday -End $tomorrow -recipient (get-mailbox $mailbox).primarysmtpaddress -ResultSize unlimited ).count $output.recieved $output| export-csv -noTypeInformation -append -path c:\temp\output.csv }