Powershell ile Exchange sunucuda kullanıcıların alınan/gönderilen mail istatistiğini almak
- Enis GOKTAY
- 28 Ara 2012
- 2 dakikada okunur
Bazen yöneticinizden “Şirketimizdeki tüm kullanıcıların son bir ayda kaç adet email alıp/göndermiş” gibi bir isteğiyle karşılaşarbilirsiniz.
Aşağıdaki powershell scripti tam burada işinize yarayabilir.
# Aramanin yapilacagi ilk tarih
$Start = (Get-Date -Hour 00 -Minute 00 -Second 00).AddDays(-1)
# Aramanin yapilacagi son tarih
$End = (Get-Date -Hour 23 -Minute 59 -Second 59).AddDays(-1)
# CSV file için olusturulacak tarih formati
$date = get-date -Format MM-dd-yyyy
# Declare an array to store the results
$Results = @()
# SEND Eventlerini tracking loglardan alinmasi
$Sent = Get-MessageTrackingLog -Server exc_server -Start $Start -End $End -resultsize unlimited | Where { $_.EventID -eq 'Send' -or $_.EventID -eq 'Deliver' }
# RECEIVE Eventlerini tracking loglardan alinmasi
$Received = Get-MessageTrackingLog -Server exc_server -Start $Start -End $End -resultsize unlimited | Where { $_.EventID -eq 'Receive' -or $_.EventID -eq 'TRANSFER' }
# Raporda almak istedigimiz mailboxlar;
# Bu case için bir günlük loglarin çoklu DB'lerden alinmasi
$Mailboxes = Get-Mailbox
# Sayaçlari progress olarak görülmesi
$Total = $Mailboxes.Count
$Count = 1
# Her mailbox ve pipe için
$Mailboxes | Sort-Object DisplayName | ForEach-Object {
# Progress bar için update
$PercentComplete = $Count / $Total * 100
Write-Progress -Activity "Message Tracking Log Search" -Status "Processing mailboxes" -percentComplete $PercentComplete
# Stat degiskenine atanmasi
$Stats = "" | Select-Object Name,Sent,Received
# Her mailbox için email adresi alinmasi
$Email = $_.WindowsEmailAddress.ToString()
# Mailbox'in görünen adi için objemizin isim özellikleri ayarlanmasi
$Stats.Name = $_.DisplayName
# Gönderilen mailler için
$Stats.Sent = ($Sent | Where-Object { ($_.EventId -eq "Send" -or $_.EventID -eq "Deliver") -and ($_.Sender -eq $email) }).Count
# Alinan mailler için
$Stats.Received = ($Received | Where-Object { ($_.EventId -eq "RECEIVE") -and ($_.Recipients -match $email) }).Count
# Sonuç bölümüne mailbox için istatistic eklenmesi
$Results += $Stats
# Progress bar için sayacin bir azaltilmasi
$Count += 1
}
# Sonuç
$Results | Export-CSV C:\send_receive_log-$date.csv -NoType -Encoding utf8
Comments