none
PowerShell script to count messages sent from mailboxes in a distribution group.

    Question

  • Hi All,

    I was wondering if someone could help me on this one.

    I am trying to find a powershell script that will count and report to either CSV or HTML the number of sent emails between a period of time for each mailbox in a specific distribution group.

    I am no powershell user and so far I have managed -

    get-messagetrackinglog -server "<hub server>" -Resultsize "Unlimited" -Sender "<email address>" -Start "03/01/2012 00:00:00" -End "04/01/2012 00:00:00" | Measure-Object | Convertto-Html Count, Sender | Set-Content C:\temp\usermailout.html

    But obviously this only reports on a single user, I need something that will pick the mailboxes out of the distribution group and report the sent count.

    Any advise would be much appreciated.

    Si

    Friday, May 11, 2012 6:52 AM

Answers

  • Hi Si,

    This is one script I wrote to count message sent from mailboxes in a distribution group, hope can give you some help:

    $Members=Get-DistributionGroupMember -identity GroupName

    Foreach($user in $Members){

    $Emailaddress=$User.PrimarySmtpAddress.ToString()

    Get-MessageTrackingLog -Sender $Emailaddress -Start "03/01/2012 00:00:00" -End "04/01/2012 00:00:00"| Measure-Object| Select Count, @{Name='Sender'; Expression={[String]::join(";", $Emailaddress)}}| ConvertTo-Html| add-Content C:\temp\usermailout.html

    }

    Thanks,

    Evan Liu

    TechNet Subscriber Support in forum

    If you have any feedback on our support, please contact tngfb@microsoft.com  


    Evan Liu

    TechNet Community Support


    Monday, May 14, 2012 6:34 AM
    Moderator

All replies

  • Hi Si,

    This is one script I wrote to count message sent from mailboxes in a distribution group, hope can give you some help:

    $Members=Get-DistributionGroupMember -identity GroupName

    Foreach($user in $Members){

    $Emailaddress=$User.PrimarySmtpAddress.ToString()

    Get-MessageTrackingLog -Sender $Emailaddress -Start "03/01/2012 00:00:00" -End "04/01/2012 00:00:00"| Measure-Object| Select Count, @{Name='Sender'; Expression={[String]::join(";", $Emailaddress)}}| ConvertTo-Html| add-Content C:\temp\usermailout.html

    }

    Thanks,

    Evan Liu

    TechNet Subscriber Support in forum

    If you have any feedback on our support, please contact tngfb@microsoft.com  


    Evan Liu

    TechNet Community Support


    Monday, May 14, 2012 6:34 AM
    Moderator
  • Hi Evan,

    That worked like a charm, thanks very much.

    Si

    Monday, May 14, 2012 1:32 PM
  • Hi there,

    Thanks for this, I hate to beg for more, but how would I modify this to name each mailbox? Right now it just states

    Count Sender
    <Number of E-mails>

    With no way of identifying which mailbox it is.

    I was also interested in doing something similar to view the number of mails received if this is at all possible?

    Thanks in advance

    Paddy

    Tuesday, May 15, 2012 9:57 AM
  • Hi Paddy,

    If you need identity the mailbox, you can this change in the commands:

    $Name=$User.Name

    Get-MessageTrackingLog -Sender $Emailaddress -Start "03/01/2012 00:00:00" -End "04/01/2012 00:00:00"| Measure-Object| Select Count, @{Name='Sender'; Expression={[String]::join(";", $Emailaddress)}}, @{Name='Identity'; Expression={[String]::join(";", $Name)}} | ConvertTo-Html| add-Content C:\temp\usermailout.html

    I was also interested in doing something similar to view the number of mails received if this is at all possible?

    You can do like this:

    get-messagetrackinglog -Sender "<email address>" -Start "03/01/2012 00:00:00" -End "04/01/2012 00:00:00" -EventID RECEIVE| Measure-Object

    This way you can view the number of user receive the emails.

    If you have any other question this issue, I suggest you open a new thread in the forum.

    Thanks for your understanding.

    Evan Liu

    TechNet Subscriber Support in forum

    If you have any feedback on our support, please contacttngfb@microsoft.com 


    Evan Liu

    TechNet Community Support

    Tuesday, May 15, 2012 10:13 AM
    Moderator
  • Hi Evan,

    I want to know the number of emails sent to my distribution group. How do I find out the count ?

    Please advise

    Thanks

    Monday, March 24, 2014 7:15 PM