I am trying to get a monthly report of received e-mails from a list of e-mail-addresses. I want to export the results to a .csv and if possible send the csv automatically via e-mail to another address.
This is my approach in the exchange-management-shell looks like this but isn't creating any data in the .csv
$mail = @("mymail@mydomain.com","another@mydomain.com")
$(foreach ($name in $mail)
{
$startofmonth = Get-Date -format MM/dd/yyyy -day 1 -hour 0 -minute 0 -second 0
$endofmonth = ((Get-Date -day 1 -hour 0 -minute 0 -second 0).AddMonths(1).AddSeconds(-1))
$endofmonth = "{0:MM/dd/yy}" -f [datetime]$endofmonth
$results = (Get-MessageTrackingLog -ResultSize unlimited -recipients $name -Start $startofmonth -End $endofmonth -EventId RECEIVE).count
$results
}) | Export-CSV -path \\mymachine\c$\output.csv -NoTypeInformation
How do I get the data that I want like this in the .csv:
mailaddress | count(received mails) | timeframe