Hi
I wonder if anyone can explain this behaviour please.
I am trying to run a simple script on an Exchange 2010 server, it's a single server setup (SBS2011) and the client wants a list of the number of emails sent and received each week, which seemed fine (actually not because - see below), but then they said 'can you exclude internal mails' so only externally sent and received, and this is where things have stopped working.
The script (with comments) thus far is:
#Get all primary email addresses into an array $emailaddresses = get-recipient -resultsize unlimited #Set the date range to the last 7 days $date = get-date(get-date).addhours(-168) #echo headers for the CSV echo "Email Address, incoming, Outgoing" #enumerate the email addresses foreach ($emailaddress in $emailaddresses) { $incoming = (get-messagetrackinglog -ResultSize Unlimited -Recipient $emailaddress.primarysmtpaddress -Start $date -eventID "RECEIVE" | where{$_.Source -eq "SMTP"} | select timestamp, messageid, messagesubject, sender, {$_.recipients}, totalbytes, recipientcount).count $outgoing = (get-messagetrackinglog -ResultSize Unlimited -sender $emailaddress.primarysmtpaddress -Start $date -eventID "TRANSFER" | select timestamp, messageid, messagesubject, sender, {$_.recipients}, totalbytes, recipientcount).count if (!$incoming) {$incoming = 0} if (!$outgoing) {$outgoing = 0} #output the email address, number of incoming and then number of outgoing echo ($emailaddress.primarysmtpaddress.tostring() +"," + $incoming.tostring() + "," + $outgoing.tostring()) }
So this is currently returning all 0's.
If you remove the -eventid clause and the where{$_.source -eq "smtp"} section, then you get numbers. Part of the issue is of course that a single email generates a number of transport events, so 1 sent email may generate at least 2 items in the logs.
If you run the command WITH the -eventid and where clause, but WITHOUT the .count part, then you get a list of emails as expected
What am I missing?
Thanks
===== As a wise man once said to me - have a sense of proportion.