powershell - Script to count number of emails for multiple users -
i needing little script. have working if use single email address. need add list of 8 emails addresses scan. how modify send 1 email 8 users?
i have seen scripts make html file displays in nice table ran against users in exchange , needs group of 8 users.
add-pssnapin microsoft.exchange.management.powershell.e2010 #powershell blah blah blah $nl = [environment]::newline #mailbox gather stats on $mailboxs=$mailbox= 'user1@domain.com','user2@domain.com' #get todays $startdate=get-date $enddate=get-date #subtract 1 day todays date (report ending day) , 1 day todays date (report starting day) $startdateformatted=$startdate.adddays(-1).toshortdatestring() $enddateformatted=$enddate.adddays(-1).toshortdatestring() foreach ($mailbox in $mailboxs) { # sent e-mails $sendcount = get-transportservice | get-messagetrackinglog -start "$startdateformatted 00:00:00" -end "$enddateformatted 23:59:59" -sender $mailbox -resultsize unlimited | select-object -unique messageid # received e-mails - works not on generic accounts $receivecount = get-transportservice | get-messagetrackinglog -start "$startdateformatted 00:00:00" -end "$enddateformatted 23:59:59" -recipients $mailbox -resultsize unlimited | select-object -unique messageid $sendcountstring = $sendcount.count $receivecountstring = $receivecount.count } $output = $mailbox | foreach { $resulthash = @{ address = $_ sent = $sendcountstring received = $receivecountstring } new-object -typename psobject -property $resulthash | select address,sent,received } #who send e-mail report to. #multiple e-mail addresses should in format "<email1@domain.com>, <email2@domain.com>" $mailparams = @{ = "issreports@domain.com" = "user3@domain.com" subject = "daily e-mail report iss $startdateformatted" bodyashtml = $true smtpserver = "mail.domain.com" } $header = @" "mailbox stats report date range: $startdateformatted 00:00:00 - $enddateformatted 23:59:59 "@ $body = $output | convertto-html -as table -head $header | out-string send-mailmessage @mailparams -body $body
i put script , pieces borrowed couple of own. kind of reporting, need read through logs once, , can eliminate need de-dupe messageid returning deliver events. there 1 deliver event per email sent, containing both sender , recipients.
#mailboxs gather stats on $mailbox= 'user1@domain.com','user2@domain.com' #get todays date twice $startdate=get-date $enddate=get-date #hash tables send , receive counts $sent = @{} $received = @{} #subtract 1 day todays date (report ending day) , 1 days todays date (report starting day) $startdateformatted=$startdate.adddays(-1).toshortdatestring() $enddateformatted=$enddate.adddays(-1).toshortdatestring() $transportservers = get-exchangeserver | {$_.serverrole -match "hubtransport"} | select -expandproperty name foreach ($transportserver in $transportservers) { get-messagetrackinglog -start "$startdateformatted 00:00:00" -end "$enddateformatted 23:59:59" -eventid deliver -server $transportserver -resultsize unlimited | foreach { if ($mailbox -contains $_.sender ) { $sent[$_.sender]++ } foreach ($recipient in $_.recipients) { if ($mailbox -contains $recipient ) { $received[$recipient]++ } } } } $output = $mailbox | foreach { $resulthash = @{ address = $_ sent = $sent[$_] received = $received[$_] } new-object -typename psobject -property $resulthash | select address,sent,received } #who send e-mail report to. #multiple e-mail addresses should in format "<email1@domain.com>, <email2@domain.com>" $mailparams = @{ = "issreports@domain.com" = "user3@domain.com" subject = "weekly e-mail report $mailbox $startdateformatted - $enddateformatted" bodyashtml = $true smtpserver = "mail.domain.com" } $header = @" "mailbox stats report date range: $startdateformatted 00:00:00 - $enddateformatted 23:59:59 "@ $body = $output | convertto-html -as table -head $header | out-string send-mailmessage @mailparams -body $body
Comments
Post a Comment