{"id":4392,"date":"2011-08-25T12:35:22","date_gmt":"2011-08-25T08:35:22","guid":{"rendered":"http:\/\/msbro.ru\/?p=4392"},"modified":"2013-10-11T13:41:31","modified_gmt":"2013-10-11T09:41:31","slug":"skript-statistiki-polzovatelejj-exchange","status":"publish","type":"post","link":"https:\/\/msbro.ru\/index.php\/archives\/4392","title":{"rendered":"\u0421\u043a\u0440\u0438\u043f\u0442 \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 Exchange"},"content":{"rendered":"<p>\u0410\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 Exchange 2007 \/ 2010 \u0436\u0443\u0440\u043d\u0430\u043b\u044b \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442 \u0432\u044b\u0433\u0440\u0443\u0437\u043a\u0443 \u0432 . CSV-\u0444\u0430\u0439\u043b \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. \u041e\u043d \u043d\u0430\u0445\u043e\u0434\u0438\u0442 \u0432\u0441\u0435 \u0442\u0440\u0430\u043d\u0441\u043f\u043e\u0440\u0442\u043d\u044b\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u044b.<\/p>\n<p><em>\u00a0\u0412\u0441\u0435\u0433\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0438 Bytes Sent<\/em><\/p>\n<p><em>\u0423\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u0421\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0438 Bytes Sent<\/em><\/p>\n<p><em>\u0412\u0441\u0435\u0433\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0438 \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u043e \u0431\u0430\u0439\u0442<\/em><\/p>\n<p>\u0438 \u043f\u0440\u043e\u0447\u0435\u0435&#8230;..<\/p>\n<p><!--more--><\/p>\n<pre>#mjolinor \r\n#02\/24\/2011 \r\n\r\n#requires -version 2.0 \r\n\r\n$today = get-date \r\n$rundate = $($today.adddays(-1)).toshortdatestring() \r\n\r\n$outfile_date = ([datetime]$rundate).tostring(\"yyyy_MM_dd\") \r\n$outfile = \"email_stats_\" + $outfile_date + \".csv\" \r\n\r\n$dl_stat_file = \"DL_stats.csv\" \r\n\r\n$accepted_domains = Get-AcceptedDomain |% {$_.domainname.domain} \r\n[regex]$dom_rgx = \"`(?i)(?:\" + (($accepted_domains |% {\"@\" + [regex]::escape($_)}) -join \"|\") + \")$\" \r\n\r\n$mbx_servers = Get-ExchangeServer |? {$_.serverrole -match \"Mailbox\"}|% {$_.fqdn} \r\n[regex]$mbx_rgx = \"`(?i)(?:\" + (($mbx_servers |% {\"@\" + [regex]::escape($_)}) -join \"|\") + \")\\&gt;$\" \r\n\r\n$msgid_rgx = \"^\\$\" \r\n\r\n$hts = get-exchangeserver |? {$_.serverrole -match \"hubtransport\"} |% {$_.name} \r\n\r\n$exch_addrs = @{} \r\n\r\n$msgrec = @{} \r\n$bytesrec = @{} \r\n\r\n$msgrec_exch = @{} \r\n$bytesrec_exch = @{} \r\n\r\n$msgrec_smtpext = @{} \r\n$bytesrec_smtpext = @{} \r\n\r\n$total_msgsent = @{} \r\n$total_bytessent = @{} \r\n$unique_msgsent = @{} \r\n$unique_bytessent = @{} \r\n\r\n$total_msgsent_exch = @{} \r\n$total_bytessent_exch = @{} \r\n$unique_msgsent_exch = @{} \r\n$unique_bytessent_exch = @{} \r\n\r\n$total_msgsent_smtpext = @{} \r\n$total_bytessent_smtpext = @{} \r\n$unique_msgsent_smtpext=@{} \r\n$unique_bytessent_smtpext = @{} \r\n\r\n$dl = @{} \r\n\r\n$obj_table = { \r\n@\" \r\nDate = $rundate \r\nUser = $($address.split(\"@\")[0]) \r\nDomain = $($address.split(\"@\")[1]) \r\nSent Total = $(0 + $total_msgsent[$address]) \r\nSent MB Total = $(\"{0:F2}\" -f $($total_bytessent[$address]\/1mb)) \r\nReceived Total = $(0 + $msgrec[$address]) \r\nReceived MB Total = $(\"{0:F2}\" -f $($bytesrec[$address]\/1mb)) \r\nSent Internal = $(0 + $total_msgsent_exch[$address]) \r\nSent Internal MB = $(\"{0:F2}\" -f $($total_bytessent_exch[$address]\/1mb)) \r\nSent External = $(0 + $total_msgsent_smtpext[$address]) \r\nSent External MB = $(\"{0:F2}\" -f $($total_bytessent_smtpext[$address]\/1mb)) \r\nReceived Internal = $(0 + $msgrec_exch[$address]) \r\nReceived Internal MB = $(\"{0:F2}\" -f $($bytesrec_exch[$address]\/1mb)) \r\nReceived External = $(0 + $msgrec_smtpext[$address]) \r\nReceived External MB = $(\"{0:F2}\" -f $($bytesrec_smtpext[$address]\/1mb)) \r\nSent Unique Total = $(0 + $unique_msgsent[$address]) \r\nSent Unique MB Total = $(\"{0:F2}\" -f $($unique_bytessent[$address]\/1mb)) \r\nSent Internal Unique  = $(0 + $unique_msgsent_exch[$address])  \r\nSent Internal Unique MB = $(\"{0:F2}\" -f $($unique_bytessent_exch[$address]\/1mb)) \r\nSent External  Unique = $(0 + $unique_msgsent_smtpext[$address]) \r\nSent External Unique MB = $(\"{0:F2}\" -f $($unique_bytessent_smtpext[$address]\/1mb)) \r\n\"@ \r\n} \r\n\r\n$props = $obj_table.ToString().Split(\"`n\")|% {if ($_ -match \"(.+)=\"){$matches[1].trim()}} \r\n\r\n$stat_recs = @() \r\n\r\nfunction time_pipeline { \r\nparam ($increment  = 1000) \r\nbegin{$i=0;$timer = [diagnostics.stopwatch]::startnew()} \r\nprocess { \r\n    $i++ \r\n    if (!($i % $increment)){Write-host \u201c`rProcessed $i in $($timer.elapsed.totalseconds) seconds\u201d -nonewline} \r\n    $_ \r\n    } \r\nend { \r\n    write-host \u201c`rProcessed $i log records in $($timer.elapsed.totalseconds) seconds\u201d \r\n    Write-Host \"   Average rate: $([int]($i\/$timer.elapsed.totalseconds)) log recs\/sec.\" \r\n    } \r\n} \r\n\r\nforeach ($ht in $hts){ \r\n\r\n    Write-Host \"`nStarted processing $ht\" \r\n\r\n    get-messagetrackinglog -Server $ht -Start \"$rundate\" -End \"$rundate 11:59:59 PM\" -resultsize unlimited | \r\n    time_pipeline |%{ \r\n\r\n    if ($_.eventid -eq \"DELIVER\" -and $_.source -eq \"STOREDRIVER\"){ \r\n\r\n        if ($_.messageid -match $mbx_rgx -and $_.sender -match $dom_rgx) { \r\n\r\n            $total_msgsent[$_.sender] += $_.recipientcount \r\n            $total_bytessent[$_.sender] += ($_.recipientcount * $_.totalbytes) \r\n            $total_msgsent_exch[$_.sender] += $_.recipientcount \r\n            $total_bytessent_exch[$_.sender] += ($_.totalbytes * $_.recipientcount) \r\n\r\n            foreach ($rcpt in $_.recipients){ \r\n            $exch_addrs[$rcpt] ++ \r\n            $msgrec[$rcpt] ++ \r\n            $bytesrec[$rcpt] += $_.totalbytes \r\n            $msgrec_exch[$rcpt] ++ \r\n            $bytesrec_exch[$rcpt] += $_.totalbytes \r\n            } \r\n\r\n        } \r\n\r\n        else { \r\n            if ($_messageid -match $messageid_rgx){ \r\n                    foreach ($rcpt in $_.recipients){ \r\n                        $msgrec[$rcpt] ++ \r\n                        $bytesrec[$rcpt] += $_.totalbytes \r\n                        $msgrec_smtpext[$rcpt] ++ \r\n                        $bytesrec_smtpext[$rcpt] += $_.totalbytes \r\n                    } \r\n                } \r\n\r\n            } \r\n\r\n    } \r\n\r\n    if ($_.eventid -eq \"RECEIVE\" -and $_.source -eq \"STOREDRIVER\"){ \r\n        $exch_addrs[$_.sender] ++ \r\n        $unique_msgsent[$_.sender] ++ \r\n        $unique_bytessent[$_.sender] += $_.totalbytes \r\n\r\n            if ($_.recipients -match $dom_rgx){ \r\n                $unique_msgsent_exch[$_.sender] ++ \r\n                $unique_bytessent_exch[$_.sender] += $_.totalbytes \r\n                } \r\n\r\n            if ($_.recipients -notmatch $dom_rgx){ \r\n                $ext_count = ($_.recipients -notmatch $dom_rgx).count \r\n                $unique_msgsent_smtpext[$_.sender] ++ \r\n                $unique_bytessent_smtpext[$_.sender] += $_.totalbytes \r\n                $total_msgsent[$_.sender] += $ext_count \r\n                $total_bytessent[$_.sender] += ($ext_count * $_.totalbytes) \r\n                $total_msgsent_smtpext[$_.sender] += $ext_count \r\n                 $total_bytessent_smtpext[$_.sender] += ($ext_count * $_.totalbytes) \r\n                } \r\n\r\n        } \r\n\r\n    if ($_.eventid -eq \"expand\"){ \r\n        $dl[$_.relatedrecipientaddress] ++ \r\n        } \r\n    }      \r\n\r\n} \r\n\r\nforeach ($address in $exch_addrs.keys){ \r\n\r\n$stat_rec = (new-object psobject -property (ConvertFrom-StringData (&amp;$obj_table))) \r\n$stat_recs += $stat_rec | select $props \r\n} \r\n\r\n$stat_recs | export-csv $outfile -notype  \r\n\r\nif (Test-Path $dl_stat_file){ \r\n    $DL_stats = Import-Csv $dl_stat_file \r\n    $dl_list = $dl_stats |% {$_.address} \r\n    } \r\n\r\nelse { \r\n    $dl_list = @() \r\n    $DL_stats = @() \r\n    } \r\n\r\n$DL_stats |% { \r\n    if ($dl[$_.address]){ \r\n        if ([datetime]$_.lastused -le [datetime]$rundate){  \r\n            $_.used = [int]$_.used + [int]$dl[$_.address] \r\n            $_.lastused = $rundate \r\n            } \r\n        } \r\n} \r\n\r\n$dl.keys |% { \r\n    if ($dl_list -notcontains $_){ \r\n        $new_rec = \"\" | select Address,Used,Since,LastUsed \r\n        $new_rec.address = $_ \r\n        $new_rec.used = $dl[$_] \r\n        $new_rec.Since = $rundate \r\n        $new_rec.lastused = $rundate \r\n        $dl_stats += @($new_rec) \r\n    } \r\n} \r\n\r\n$dl_stats | Export-Csv $dl_stat_file -NoTypeInformation -force \r\n\r\nWrite-Host \"`nRun time was $(((get-date) - $today).totalseconds) seconds.\" \r\nWrite-Host \"Email stats file is $outfile\" \r\nWrite-Host \"DL usage stats file is $dl_stat_file\" \r\n\r\n#Contact information \r\n#[string](0..33|%{[char][int](46+(\"686552495351636652556262185355647068516270555358646562655775 0645570\").substring(($_*2),2))})-replace \" \"<\/pre>\n<p><a href=\"http:\/\/gallery.technet.microsoft.com\/scriptcenter\/bb94b422-eb9e-4c53-a454-f7da6ddfb5d6\" target=\"_blank\">\u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a<\/a><\/p>\n<p>\u043f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u0441\u043a\u0440\u0438\u043f\u0442\u0430 \u0435\u0441\u0442\u044c \u043e\u0448\u0438\u0431\u043a\u0430 \u0441 \u0434\u0430\u0442\u0430\u043c\u0438. \u041b\u0435\u0447\u0438\u0442\u0441\u044f \u043f\u0440\u043e\u0441\u0442\u043e &#8211; \u0437\u0430\u0439\u0434\u0438\u0442\u0435 \u0432 \u0440\u0435\u0433\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0435 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0438 \/ \u0432\u044b\u0431\u0435\u0440\u0435\u0442\u0435 \u0444\u043e\u0440\u043c\u0430\u0442 \u0434\u0430\u0442\u044b yyyy-MM-dd .<\/p>\n<p>\u042d\u043a\u0441\u043f\u043e\u0440\u0442 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 \u043f\u0440\u043e\u0449\u0435 \u0432\u0441\u0435\u0433\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0432 \u00a0Excel.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0410\u043d\u0430\u043b\u0438\u0437\u0438\u0440\u0443\u0435\u0442 Exchange 2007 \/ 2010 \u0436\u0443\u0440\u043d\u0430\u043b\u044b \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442 \u0432\u044b\u0433\u0440\u0443\u0437\u043a\u0443 \u0432 . CSV-\u0444\u0430\u0439\u043b \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f. \u041e\u043d \u043d\u0430\u0445\u043e\u0434\u0438\u0442 \u0432\u0441\u0435 \u0442\u0440\u0430\u043d\u0441\u043f\u043e\u0440\u0442\u043d\u044b\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u044b. \u00a0\u0412\u0441\u0435\u0433\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0438 Bytes Sent \u0423\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0435 \u0421\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0438 Bytes Sent \u0412\u0441\u0435\u0433\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439 \u0438 \u041f\u043e\u043b\u0443\u0447\u0435\u043d\u043e \u0431\u0430\u0439\u0442 \u0438 \u043f\u0440\u043e\u0447\u0435\u0435&#8230;..<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,10],"tags":[1732,612,29,1337,955],"class_list":["post-4392","post","type-post","status-publish","format-standard","hentry","category-exchange","category-scripts","tag-exchange","tag-exchange-2007","tag-exchange-2010","tag-satistika","tag-skripty"],"_links":{"self":[{"href":"https:\/\/msbro.ru\/index.php\/wp-json\/wp\/v2\/posts\/4392"}],"collection":[{"href":"https:\/\/msbro.ru\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/msbro.ru\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/msbro.ru\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/msbro.ru\/index.php\/wp-json\/wp\/v2\/comments?post=4392"}],"version-history":[{"count":0,"href":"https:\/\/msbro.ru\/index.php\/wp-json\/wp\/v2\/posts\/4392\/revisions"}],"wp:attachment":[{"href":"https:\/\/msbro.ru\/index.php\/wp-json\/wp\/v2\/media?parent=4392"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/msbro.ru\/index.php\/wp-json\/wp\/v2\/categories?post=4392"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/msbro.ru\/index.php\/wp-json\/wp\/v2\/tags?post=4392"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}<!-- WP Super Cache is installed but broken. The constant WPCACHEHOME must be set in the file wp-config.php and point at the WP Super Cache plugin directory. -->