获取收件箱列表中每月收到的邮件数量

Get monthly count of received mails in list of inboxes

我正在尝试从电子邮件地址列表中获取收到的电子邮件的月度报告。我想将结果导出到 .csv,如果可能的话,通过电子邮件将 csv 自动发送到另一个地址。

这是我在交换管理中的方法-shell 看起来像这样,但没有在 .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

如何在 .csv 中获取我想要的数据:

mailaddress | count(received mails) | timeframe

您可以为每个结果创建自定义对象,return 将其创建到数组 $output。然后将数组转换成CSV格式输出到文件中。

$mail = @("mymail@mydomain.com","another@mydomain.com")
$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

[Array]$output = foreach ($name in $mail) {

    $results = (Get-MessageTrackingLog -ResultSize unlimited -recipients $name -Start $startofmonth -End $endofmonth -EventId RECEIVE).count

    [pscustomobject]@{
        Name=$name;
        Received=$results;
        StartTime=$startofmonth;
        EndTime=$endofmonth;
    }
}

$output | ConvertTo-Csv -NoTypeInformation | Out-File -FilePath \mymachine\c$\output.csv -Append 

这将 return 一个 CSV 文件,如下所示:

"Name","Received","StartTime","EndTime"
"mymail@mydomain.com","222","10/01/2016","10/31/16"
"another@mydomain.com","340","10/01/2016","10/31/16"

试一试:

 $mails = ("mymail@mydomain.com","another@mydomain.com")
 $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


 Get-MessageTrackingLog -ResultSize Unlimited -Start $startofmonth -End  $endofmonth -EventId RECEIVE | where{$_.Recipients -in   $mails} | select- object  Timestamp,SourceContext,Source,EventId,MessageSubject,Sender, {$_.Recipients} | 
group-object -property Timestamp |
export-csv C:\temp\MessageTrackingLogResults.csv