locked
PowerShell - Message Tracking RRS feed

  • Question

  • Hey Guys,

    I am trying to get this command to work :

    Get-ExchangeServer | Where {$_.IsHubTransportServer -eq $True -or $_.IsMailboxServer -eq $True} | Get-MessageTrackingLog -Start "06/05/2014" -End "06/06/2014" -ResultSize Unlimited |Where {$_.Recipients -eq user222@domain.com -or
    $_.Recipients -eq "user@domain.com" -or
    $_.Recipients -eq "user22@domain.com"} | Group-Object -Property Recipients | Select-Object Source,Sender,Recipients,Count | sort count -desc

    The command runs however I get Source, Sender, Recipients as Blank Values (just the header shows), the Count Works and I get values (As expected).

    Any Ideas?

    Thanks,

    Robert


    Robert


    Friday, June 6, 2014 3:12 AM

Answers

  • ah, yes, agree that it's easy with powershell but my point is, you can not do both together, getting/exporting result and counting the entries at the same time, you can first save it in a variable like this...

    $Tracking = Get-ExchangeServer | Where {$_.IsHubTransportServer -eq $True -or $_.IsMailboxServer -eq $True} | Get-MessageTrackingLog -Start "06/05/2014" -End "06/06/2014" -ResultSize Unlimited | Where {$_.Recipients -eq user222@domain.com -or $_.Recipients -eq "user@domain.com" -or $_.Recipients -eq "user22@domain.com"} | Select-Object Source,Sender,{$_.Recipients}

    Then once result is saved, you can export it and you can just use $tracking | Group-Object -Property Recipients | sort count -desc to get count, saving the result into a variable is because you don't have to run the cmdlet (which is again time consuming) again just to count the entries... 


    Blog | Get Your Exchange Powershell Tip of the Day from here

    Friday, June 6, 2014 5:24 PM
  • ah right, I have added |Select while storing them into variable, didn't I? That's the problem...

    Here are your three cmdlets...

    $Tracking = Get-ExchangeServer | Where {$_.IsHubTransportServer -eq $True -or $_.IsMailboxServer -eq $True} | Get-MessageTrackingLog -Start "06/05/2014" -End "06/06/2014" -ResultSize Unlimited | Where {$_.Recipients -eq user222@domain.com -or $_.Recipients -eq "user@domain.com" -or $_.Recipients -eq "user22@domain.com"}
    
    $tracking | Select-Object Source,Sender,{$_.Recipients}
    
    $tracking | Group-Object -Property Recipients | sort count -desc


    Blog | Get Your Exchange Powershell Tip of the Day from here

    Friday, June 6, 2014 7:50 PM

All replies

  • Because you are grouping to Recipients with "Group-Object -Property Recipients"  and once you group it, you will have different display table, just count, grouping property and other values will be in a group so you won't get Source,Sender,Recipients, in the selection individually...

    You will understand better when you run just this... 

    Get-ExchangeServer | Where {$_.IsHubTransportServer -eq $True -or $_.IsMailboxServer -eq $True} | Get-MessageTrackingLog -Start "06/05/2014" -End "06/06/2014" -ResultSize Unlimited |Where {$_.Recipients -eq user222@domain.com -or $_.Recipients -eq "user@domain.com" -or $_.Recipients -eq "user22@domain.com"} | Group-Object -Property Recipients | select *

    Better to export things to CSV first and you can get total count there using below cmdlet...

    Get-ExchangeServer | Where {$_.IsHubTransportServer -eq $True -or $_.IsMailboxServer -eq $True} | Get-MessageTrackingLog -Start "06/05/2014" -End "06/06/2014" -ResultSize Unlimited | Where {$_.Recipients -eq user222@domain.com -or $_.Recipients -eq "user@domain.com" -or $_.Recipients -eq "user22@domain.com"} | Select-Object Source,Sender,{$_.Recipients} | Export-csv Tracking.csv



    Blog | Get Your Exchange Powershell Tip of the Day from here


    • Edited by Amit Tank Friday, June 6, 2014 3:57 AM
    • Proposed as answer by Amit Tank Friday, June 6, 2014 3:57 AM
    Friday, June 6, 2014 3:53 AM
  • Amit,

    Thanks for the response. The problem I have is this: this is a huge environment with thousands of emails sent daily. I need to run my script for a period of 30 days (I may have to break this into scripts that gather data 1 week at a time). Is there anyway that I can group or count based on my script? To me it seems like its "Easy" to do with powershell

    Thanks,

    Robert


    Robert

    Friday, June 6, 2014 4:48 PM
  • ah, yes, agree that it's easy with powershell but my point is, you can not do both together, getting/exporting result and counting the entries at the same time, you can first save it in a variable like this...

    $Tracking = Get-ExchangeServer | Where {$_.IsHubTransportServer -eq $True -or $_.IsMailboxServer -eq $True} | Get-MessageTrackingLog -Start "06/05/2014" -End "06/06/2014" -ResultSize Unlimited | Where {$_.Recipients -eq user222@domain.com -or $_.Recipients -eq "user@domain.com" -or $_.Recipients -eq "user22@domain.com"} | Select-Object Source,Sender,{$_.Recipients}

    Then once result is saved, you can export it and you can just use $tracking | Group-Object -Property Recipients | sort count -desc to get count, saving the result into a variable is because you don't have to run the cmdlet (which is again time consuming) again just to count the entries... 


    Blog | Get Your Exchange Powershell Tip of the Day from here

    Friday, June 6, 2014 5:24 PM
  • Amit,

    Thanks for your help. We're almost there:

    PS C:\Users\robert.CONTOSO> $tracking | Group-Object -Property Recipients | sort count -desc

    Count Name                      Group                                                                                                                                                                                 
    ----- ----                      -----                                                                                                                                                                                 
        3                           {@{Source=; Sender=; Recipients=; Count=107}, @{Source=; Sender=; Recipients=; Count=2}, @{Source=; Sender=; Recipients=; Count=1}}                                                   


    Robert

    Friday, June 6, 2014 7:02 PM
  • ah right, I have added |Select while storing them into variable, didn't I? That's the problem...

    Here are your three cmdlets...

    $Tracking = Get-ExchangeServer | Where {$_.IsHubTransportServer -eq $True -or $_.IsMailboxServer -eq $True} | Get-MessageTrackingLog -Start "06/05/2014" -End "06/06/2014" -ResultSize Unlimited | Where {$_.Recipients -eq user222@domain.com -or $_.Recipients -eq "user@domain.com" -or $_.Recipients -eq "user22@domain.com"}
    
    $tracking | Select-Object Source,Sender,{$_.Recipients}
    
    $tracking | Group-Object -Property Recipients | sort count -desc


    Blog | Get Your Exchange Powershell Tip of the Day from here

    Friday, June 6, 2014 7:50 PM