Wie kann man mit einer Zeile PowerShell ermitteln, wie viele E-Mails Benutzer einer Niederlassung gesendet / empfangen haben?
Hier ein Beispiel für Exchange 2010 -2016:
write-host "Collecting AD users..." -foregroundcolor yellow;$aduser=(Get-ADUser -filter * | where-object { $_.DistinguishedName -like "*,OU=Branch,*" -and $_.Enabled }).samaccountname;write-host "Collecting Message Tracking Logs of past 14 days..." -foregroundcolor yellow;Get-MailboxServer | foreach-object {$mtl+=Get-MessageTrackingLog -Server $_.name -start ("{0:yyyy-MM-dd} 00:00:00" -f (Get-Date).AddDays(-14)) -resultsize unlimited | where-object {$_.eventid -eq "SEND" -or $_.eventid -eq "DELIVER"}};$aduser | foreach -begin {$cnt_sent=0;$cnt_rec=0} -process {$usr=$_;$mb=Get-Mailbox $usr 2>$null;$dn=$mb.DisplayName;if($mb.count -eq 1){$this_cnt_sent=0;$this_cnt_rec=0;$this_cnt_sent+=($mtl | where-object { $_.sender -eq $mb.PrimarySmtpAddress -and $_.eventid -eq "SEND" }).count;$this_cnt_rec+=($mtl | where-object {$_.recipients -eq $mb.PrimarySmtpAddress -and $_.eventid -eq "DELIVER"}).count;write-host "${dn}: $this_cnt_sent sent, $this_cnt_rec received";$cnt_sent+=$this_cnt_sent;$cnt_rec+=$this_cnt_rec}} -end {write-host "Summary: $cnt_sent sent, $cnt_rec received";clear-variable mtl}
Ist schon irre, wie einfach das ist. ;-)