none
Powershell Function message tracking

    Question

  • Hello,

    Exchange 2010 with PSVersionTable 2.0

    I'm trying to create a Function that will perform a messagetracking. I would like to have the ability to pick a start time and/or an end time with recipients and senders and with a messageID. All the parameters should be optional except for Time.

    So I came up with the following script which is not working. Can someone point me in the right direction please.

    Function Get-MessageTrace {
    <#
    .SYNOPSIS
    Rerieves message Tracking Information from either Sender or/and recipient and the start
    parameter is obligatory.
    .DESCRIPTION
    This script must be run from either powershell or ISe and it needs to have the Exchange Module installed. 
    These commands will use MessageTracking on all Transport Servers and will gather by date all the messages. 
    To speed things up please filter to the left. The more information you can supply this script, the faster
    the results will be and less processing required on the server.
    #>
    
        Param(
            [DateTime]$Start= (Get-date),
            $Sender,
            $Recipients,
            $MessageID
        )
        $Exchangeservers = Get-TransportServer |where-Object {$_.name -ne "app01" -and $_.name -ne "app02"}
                    foreach ($Server in $Exchangeservers) {
                       Get-MessageTrackingLog -Server $Server.pscomputername -Start $start -sender $sender -Recipients $Recipients -MessageId $MessageID
        }
    }
    
    

    from $Exchangeservers onwards the script works without using the variables. When I use the variables the script no longer works.

    please help

    Thanks,

    Tuesday, April 03, 2018 3:54 PM

Answers

  • Hi Tiri,

    I know, you can replace the command in your script the check if any helps, as below:

    Function Get-MessageTrace { <# .SYNOPSIS Rerieves message Tracking Information from either Sender or/and recipient and the start parameter is obligatory. .DESCRIPTION This script must be run from either powershell or ISe and it needs to have the Exchange Module installed. These commands will use MessageTracking on all Transport Servers and will gather by date all the messages. To speed things up please filter to the left. The more information you can supply this script, the faster the results will be and less processing required on the server. #> Param( [DateTime]$Start= (Get-date), $Sender, $Recipients, $MessageID ) Get-TransportServer|where-Object {$_.name -ne "app01" -and $_.name -ne "app02"} |Get-MessageTrackingLog -Start $start -sender $sender -Recipients $Recipients -MessageId $MessageID

    }


    Best Regards,
    Niko Cheng


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Friday, April 06, 2018 2:07 AM
    Moderator

All replies

  • Hi Tiri,

    You don't need to use the variables, just list all transport servers and search the message tracking logs:


    Get-TransportServer|where-Object {$_.name -ne "app01" -and $_.name -ne "app02"} |Get-MessageTrackingLog -Start $start -sender $sender -Recipients $Recipients -MessageId $MessageID

    Best Regards,
    Niko Cheng


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Wednesday, April 04, 2018 3:24 AM
    Moderator
  • My intention is to work this script to finally make it a module. 
    Thursday, April 05, 2018 6:07 PM
  • Hi Tiri,

    I know, you can replace the command in your script the check if any helps, as below:

    Function Get-MessageTrace { <# .SYNOPSIS Rerieves message Tracking Information from either Sender or/and recipient and the start parameter is obligatory. .DESCRIPTION This script must be run from either powershell or ISe and it needs to have the Exchange Module installed. These commands will use MessageTracking on all Transport Servers and will gather by date all the messages. To speed things up please filter to the left. The more information you can supply this script, the faster the results will be and less processing required on the server. #> Param( [DateTime]$Start= (Get-date), $Sender, $Recipients, $MessageID ) Get-TransportServer|where-Object {$_.name -ne "app01" -and $_.name -ne "app02"} |Get-MessageTrackingLog -Start $start -sender $sender -Recipients $Recipients -MessageId $MessageID

    }


    Best Regards,
    Niko Cheng


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Friday, April 06, 2018 2:07 AM
    Moderator
  • Hi Tiri,

    Is there any update on this thread? If the issue has been resolved, please mark the helpful replies as answers, this will make answer searching in the forum easier and be beneficial to other community members as well. Thanks for your understanding.


    Best Regards,
    Niko Cheng


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnsf@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Thursday, April 12, 2018 10:05 AM
    Moderator