目标: 定期统计每个月的邮件收发量。
创新互联公司长期为超过千家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为郧西企业提供专业的成都做网站、网站建设,郧西网站改版等技术服务。拥有十载丰富建站经验和众多成功案例,为您定制开发。
Add-PSSnapin microsoft.exchange*
$Server="MBX1.liuxing.com","MBX2.liuxing.com","MBX03.liuxing.com","MBX4.liuxing.com","MBX5.liuxing.com"
$today=get-date
$m=$today.AddDays(-1)
$MonthNo=-join ($m.Year,$m.Month)
$s=($m.Month,"01",$m.Year) -join "/"
if($m.Month -eq 2) {
$e=($m.Month,"28",$m.Year) -join "/"
}
elseif($m.Month -eq 4 -or $m.Month -eq 6 -or $m.Month -eq 9 -or $m.Month -eq 11){
$e=($m.Month,"30",$m.Year) -join "/"
}
else{
$e=($m.Month,"31",$m.Year) -join "/"
}
$st="$s 00:00:00"
$et="$e 23:59:59"
$file="Reports-$MonthNo.csv"
$SCount=$RCount=$DSNCount=0
foreach($i in $Server)
{
$temp=Get-MessageTrackingLog -Server $i -Start "$st" -End "$et" -ResultSize unlimited
foreach($j in $temp){
if($j.EventId -eq "RECEIVE" -and $j.Source -eq "STOREDRIVER"){
$SCount++
}
if($j.EventId -eq "DELIVER"){
$RCount++
}
if($j.EventId -eq "DSN"){
$DSNCount++
}
}
write-output "$i send email count: $SCount" | Out-File -Append C:\reports\$file
write-output "$i receive email count: $RCount" | Out-File -Append C:\reports\$file
write-output "$i dsn email count: $DSNCount" | Out-File -Append C:\reports\$file
}