[英]Get monthly count of received mails in list of inboxes
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.
我想将结果导出到.csv,并在可能的情况下通过电子邮件自动将csv发送到另一个地址。
This is my approach in the exchange-management-shell looks like this but isn't creating any data in the .csv 这是我在exchange-management-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
How do I get the data that I want like this in the .csv: 如何在.csv中获取所需的数据:
mailaddress |
邮箱地址| count(received mails) |
计数(已接收邮件)| timeframe
大体时间
You can create a custom object for each result and return that to an array $output
. 您可以为每个结果创建一个自定义对象,并将其返回到数组
$output
。 Then convert the array into a CSV
format and output it to a file. 然后将数组转换为
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
This will return a CSV
file that looks like this: 这将返回一个如下所示的
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"
try it: 试试吧:
$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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.