Link to home
Start Free TrialLog in
Avatar of Albert Widjaja
Albert WidjajaFlag for Australia

asked on

Modifying Exchange 2013 PowerShell command to search through all MessageTransportLog ?

Hi All,

I'm in the middle of Exchange email flow troubleshooting and I need your help.

Can anyone here please assist me in modifying the below PowerShell script which only works returning the MessageTrackingLog from the server where it is connected?

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://PRODMBX03-VM/PowerShell/ -Authentication Kerberos
Import-PSSession $Session -AllowClobber
Import-Module ActiveDirectory -ErrorAction STOP

Get-TransportService | foreach { Get-Messagetrackinglog -Recipients "ITHelpDesk@mydomain.com" -Start "04/10/2017 1:00:00 AM" -End "04/10/2017 11:59:00 PM" | Select ClientIp, ClientHostname, Timestamp, EventID, Source, ServerHostname, ServerIp, Sender, Recipients, MessageSubject, TotalBytes, ConnectorId } | Export-Csv C:\Result\EmailTracking.csv -NoTypeInformation

Open in new window


What I need to get:

1. I've got 6x Exchange servers returned from the command Get-TransportService, so I wonder if it is possible to get the result from all 6 servers.
2. The time format that I am using in my country is DD/MM/YYYY
3. I need to search based on some keyword in the Subject line.

Thanks in advance.
ASKER CERTIFIED SOLUTION
Avatar of J S
J S
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Albert Widjaja

ASKER

Thanks for the quick reply Jason,

But how about the parameter to search the Subject based on certain keyword ?
You can add the following switch -MessageSubject "Subject"
Jason,

The Powershell script that you proposed does not take any piping. I used that before on Exchange 2007 and 2010, but in this case on Exchange 2013 I got this error:

The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take 
pipeline input.

Open in new window

Get-ClientAccessServer | Get-Messagetrackinglog -Recipients "ITHelpDesk@mydomain.com" -Start "04/10/2017 1:00:00 AM" -End "04/10/2017 11:59:00 PM" | Select ClientIp, ClientHostname, Timestamp, EventID, Source, ServerHostname, ServerIp, Sender, Recipients, MessageSubject, TotalBytes, ConnectorId | Export-Csv C:\Result\EmailTracking.csv -NoTypeInformation

Open in new window

 I removed the bracket } from the code.
Hi Jason,

The problem still the same:

Get-ClientAccessServer | Get-Messagetrackinglog -Recipients "ITHelpDesk@mydomain.com" -Start "04/18/2017 1:00:00 AM" -End "04/18/2017 11:59:00 PM" | Where-Object {$_.MessageSubject -contains "Payroll"}| Select ClientIp, ClientHostname, Timestamp, EventID, Source, ServerHostname, ServerIp, Sender, Recipients, MessageSubject, TotalBytes, ConnectorId | Export-Csv C:\RESULT\EmailTracking2013.csv -NoTypeInformation

Open in new window


This is the error message that I got:

The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take 
pipeline input.
    + CategoryInfo          : InvalidArgument: (PRODMBXCAS04-VM:PSObject) [Get-MessageTrackingLog], ParameterBindingException
    + FullyQualifiedErrorId : InputObjectNotBound,Get-MessageTrackingLog
    + PSComputerName        : PRODMBX02-VM
 
The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take 
pipeline input.
    + CategoryInfo          : InvalidArgument: (PRODMBXCAS02-VM:PSObject) [Get-MessageTrackingLog], ParameterBindingException
    + FullyQualifiedErrorId : InputObjectNotBound,Get-MessageTrackingLog
    + PSComputerName        : PRODMBX02-VM

Open in new window

Get-ClientAccessServer | Get-Messagetrackinglog -Recipients "ITHelpDesk@mydomain.com" -Start "04/18/2017 1:00:00 AM" -End "04/18/2017 11:59:00 PM" -MessageSubject "Payroll"| Select ClientIp, ClientHostname, Timestamp, EventID, Source, ServerHostname, ServerIp, Sender, Recipients, MessageSubject, TotalBytes, ConnectorId | Export-Csv C:\RESULT\EmailTracking2013.csv -NoTypeInformation

Open in new window

 The MessageSubject switch does not require wildcards * as it will return any subject with the match in it.
Still it does not work Jason ?


I have tried the three lines below to achieve my goals above as per the example in https://technet.microsoft.com/en-us/library/bb124926(v=exchg.150).aspx :

Get-ExchangeServer | where {$_.isHubTransportServer -eq $true -or $_.isMailboxServer -eq $true} | Get-MessageTrackingLog -Recipients "ITHelpdesk@MyDomain.com" -Start "04/18/2017 1:00:00 AM" -End "04/18/2017 11:59:00 PM" | Where-Object {$_.MessageSubject -contains "Payroll"} | Select ClientIp, ClientHostname, Timestamp, EventID, Source, ServerHostname, ServerIp, Sender, Recipients, MessageSubject, TotalBytes, ConnectorId | Export-Csv C:\TEMP\EmailTracking2013.csv -NoTypeInformation

Get-TransportServer | Get-MessageTrackingLog -Recipients "ITHelpdesk@MyDomain.com" -Start "04/18/2017 1:00:00 AM" -End "04/18/2017 11:59:00 PM" | Where-Object {$_.MessageSubject -contains "Payroll"} | Select ClientIp, ClientHostname, Timestamp, EventID, Source, ServerHostname, ServerIp, Sender, Recipients, MessageSubject, TotalBytes, ConnectorId | Export-Csv C:\TEMP\EmailTracking2013.csv -NoTypeInformation

Get-TransportService | Get-MessageTrackingLog -Recipients "ITHelpdesk@MyDomain.com" -Start "04/18/2017 1:00:00 AM" -End "04/18/2017 11:59:00 PM" | Where-Object {$_.MessageSubject -contains "Payroll"} | Select ClientIp, ClientHostname, Timestamp, EventID, Source, ServerHostname, ServerIp, Sender, Recipients, MessageSubject, TotalBytes, ConnectorId | Export-Csv C:\TEMP\EmailTracking2013.csv -NoTypeInformation

Open in new window


But all of them returns the empty.CSV file and the below error message:

The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take 
pipeline input.
    + CategoryInfo          : InvalidArgument: (PRODMBXCAS04-VM:PSObject) [Get-MessageTrackingLog], ParameterBindingException
    + FullyQualifiedErrorId : InputObjectNotBound,Get-MessageTrackingLog
    + PSComputerName        : PRODMBX01-VM
 
The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take 
pipeline input.
    + CategoryInfo          : InvalidArgument: (PRODMBXCAS04-VM:PSObject) [Get-MessageTrackingLog], ParameterBindingException
    + FullyQualifiedErrorId : InputObjectNotBound,Get-MessageTrackingLog
    + PSComputerName        : PRODMBX01-VM
 
The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take 
pipeline input.
    + CategoryInfo          : InvalidArgument: (PRODMBXCAS01-VM:PSObject) [Get-MessageTrackingLog], ParameterBindingException
    + FullyQualifiedErrorId : InputObjectNotBound,Get-MessageTrackingLog
    + PSComputerName        : PRODMBX01-VM
 
The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take 
pipeline input.
    + CategoryInfo          : InvalidArgument: (PRODMBX01-VM:PSObject) [Get-MessageTrackingLog], ParameterBindingException
    + FullyQualifiedErrorId : InputObjectNotBound,Get-MessageTrackingLog
    + PSComputerName        : PRODMBX01-VM
 
The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match any of the parameters that take 
pipeline input.
    + CategoryInfo          : InvalidArgument: (PRODMBX02-VM:PSObject) [Get-MessageTrackingLog], ParameterBindingException
    + FullyQualifiedErrorId : InputObjectNotBound,Get-MessageTrackingLog
    + PSComputerName        : PRODMBX01-VM

Open in new window

Ok are you using Exchange Management Shell? If so are you executing it with Organization level permissions and elevated as administrator?
Hi Jason,

I'm the Exchange Org. Administrator and I am executing those script from my PowerShell IDE with the below script header that I run once to just one Exchange server:
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://PRODMBX03-VM/PowerShell/ -Authentication Kerberos
Import-PSSession $Session -AllowClobber
Import-Module ActiveDirectory -ErrorAction STOP

Open in new window

If possible I would try the command provided directly from EMS. It looks like your PSSSession is not recognizing Get-MessageTrackinglog.
Ok, so is there any other way than to connect to each 6 different server running the same PowerShell command from the EMS ?
Basically the command provided with do all of the work required. It will grab all of your cas servers in the enviroment (get-clientaccessserver) and passes the get-messagetrackinglog command specifying that server.  Running the command from one server will grab the search the logs on every cas server in your environment. That is of course is servers located in the same Exchange domain.