I have a customer who has standard journaling configured for a single mailbox database. They have a need to generate a quarterly report on the number of messages that are journaled with a breakdown of messages by mailbox. I generated a script that works for a single mail recipient. The script follows:
$StartDate = Read-Host -Prompt 'Enter the start date (m/d/yyyy)' $EndDate = Read-Host -Prompt 'Enter the stop date (m/d/yyyy)' $ReportRecipient = Read-Host 'Enter the email address to receive this report: ' $msgsreceived = Get-TransportServer | Get-MessageTrackingLog -Recipients "journalmailbox@domain.com" -resultsize unlimited -start $StartDate -end $EndDate -EventID Receive $msgsreceived | Select-Object sender,timestamp,messagesubject | ft -AutoSize | Out-file C:\temp2\GetMessageCountResults.csv $count = "Number of messages" + $msgsreceived.count $count | Out-file -Append C:\temp2\GetMessageCountResults.csv Send-MailMessage -SmtpServer servername -to $ReportRecipient -From servername@domain.com -Subject "Journal message count from $startDate to $EndDate" -Body "Attached is the Journal Message count" -Attachments C:\temp2\GetMessageCountResults.csv
Now that I know that the script works on a single mailbox, I need to get it to work on all mailboxes in a mailbox database so the script doesn't need to be adjusted each time a mailbox gets added or removed from the database. I tried to include a foreach-object statement but it produced an error. The modified script looks like this:
$StartDate = Read-Host -Prompt 'Enter the start date (m/d/yyyy)' $EndDate = Read-Host -Prompt 'Enter the stop date (m/d/yyyy)' $ReportRecipient = Read-Host 'Enter the email address to receive this report: ' $msgsreceived = Get-TransportServer | Get-MessageTrackingLog -Recipients "mrwj@mvsb.com" -resultsize unlimited -start $StartDate -end $EndDate -EventID Receive $msgsreceived | Select-Object sender,timestamp,messagesubject | ft -AutoSize | Out-file C:\temp2\GetMessageCountResults.csv $count = "Number of messages" + $msgsreceived.count $count | Out-file -Append C:\temp2\GetMessageCountResults.csv Send-MailMessage -SmtpServer nhmbexch2 -to $ReportRecipient -From nhmbexch2@nhmutual.com -Subject "Journal message count from $startDate to $EndDate" -Body "Attached is the Journal Message count" -Attachments C:\temp2\GetMessageCountResults.csv
I can use some help with this.