``` Add-PSSnapin *exchange* if (Get-Item D:\scripts\mailsendreceive.html) { Remove-Item D:\scripts\mailsendreceive.html -Confirm:$false Write-Host -ForegroundColor Green "start checking tracking log,pls wait...." } else { Write-Host -ForegroundColor Green "start checking tracking log,pls wait...." } Write-Host -ForegroundColor Red "用户名,接收邮件数,发送邮件数” $emaild=Import-Csv D:\scripts\email.csv -Encoding Default $e=$emaild.email $send=$null $receive=$null $allitem=$null $cool=$null foreach ($i in $e) { $receive++ $send++ $receive=Get-TransportService | Get-MessageTrackingLog -Sender $i -ResultSize unlimited -Start "2016/12/15 12:00:00" -End "2017/01/15 12:00:00" -EventId Receive $send=Get-TransportService | Get-MessageTrackingLog -Sender $i -ResultSize unlimited -Start "2016/12/15 12:00:00" -End "2017/01/15 12:00:00" -EventId deliver $re=$receive.Count $se=$send.Count $allitem="$i,$re,$se" $allitem $cool = New-Object psobject $cool | Add-Member -MemberType NoteProperty -Name 用户名 -Value $i $cool | Add-Member -MemberType NoteProperty -Name 接收邮件数 -Value $re $cool | Add-Member -MemberType NoteProperty -Name 发送邮件数 -Value $se $cool | Sort-Object 用户名 -Descending | ConvertTo-Html | Out-File -Append D:\scripts\mailsendreceive.html } Write-Host "done!" -ForegroundColor Green ``` 您也可以关注下方微信公众号获取更多内容 ![](https://s1.51cto.com/images/blog/201903/24/8e504a9e795d73985e214f392a4f9d08.jpg?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)