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
您也可以关注下方微信公众号获取更多内容