none
Get-MessageTrackingLogs {$_.Recipients} RRS feed

  • Question

  • Trying to output the list of results in the "Recipients" column to my datagrid. Below is my working code...

    			JobScript = {
    Param ($global:usercred,
    $global:SenderAddress,
    $global:RecipientAddress,
    $global:StartDate,
    $global:EndDate)

    $s = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://pse.domain.com/powershell -Credential $global:usercred -Authentication Kerberos -ErrorAction SilentlyContinue
    Import-Module (Import-PSSession $s -AllowClobber -DisableNameChecking) -DisableNameChecking

    $servers = Get-MailboxServer | where { $_.name -like "servers*" } | select -ExpandProperty Name
    $Table = @()
    foreach ($item in $servers)
    {
    $result = Get-MessageTrackingLog -Server $item -Sender $global:SenderAddress -Recipients $global:RecipientAddress -start $global:StartDate -end $global:EndDate -ResultSize Unlimited
    $Table += $result
    }

    $Table

    CompletedScript = { Param ($Job) $results = Receive-Job -Job $Job $DT = ConvertTo-DataTable -InputObject $results $DT2 = $DT | select Timestamp, MessageId, TotalBytes, Directionality, ConnectorId, RecipientCount, EventID, Source, Sender, { $_.Recipients }, MessageSubject $global:DT3 = ConvertTo-DataTable -InputObject $DT2 $datagridview1.DataSource = $global:DT3


    I am using ConvertTo-DataTable in Powershell Studio so that I can have the columns sorted upon mouse click, as that is the only way to achieve this. All of the columns are populated correctly except the Recipients column. I thought by using {$_.} it would expand the list, but it appears to be treated differently here.. Here is the error I get when I run my program...

    ERROR: +                             $row.Item($prop.Name) = $prop.Value
    ERROR: +                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ERROR:     + CategoryInfo          : NotSpecified: (:) [], SetValueInvocationException
    ERROR:     + FullyQualifiedErrorId : CatchFromBaseAdapterParameterizedPropertySetValue
    ERROR:
    ERROR: Exception setting "Item": "Exception calling "set_Item" with "2" argument(s): "Type of value has a mismatch with column typeCouldn't store
    ERROR: <Jane.Doe@Domain.com> in  $_.Recipients  Column.  Expected type is Object[].""
    MainForm.psf (527, 7): ERROR: At Line: 527 char: 7
    ERROR: +                             $row.Item($prop.Name) = $prop.Value
    ERROR: +                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ERROR:     + CategoryInfo          : NotSpecified: (:) [], SetValueInvocationException
    ERROR:     + FullyQualifiedErrorId : CatchFromBaseAdapterParameterizedPropertySetValue
    ERROR:


    • Edited by RK-33 Friday, May 24, 2019 7:45 PM
    Friday, May 24, 2019 6:12 PM

All replies

  • Hi RK-33,

    Could you describe about the purpose that you want to achieve from this script? It will help us to narrow errors for you.

    Does it is an completed script? It seems missing two "}" in this script.

    Regards,

    Kyle Xu


    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.

    Monday, May 27, 2019 6:04 AM
    Moderator
  • The purpose of the form is for message tracking. I am trying to take the list of recipients and output it to a datagrid column. All the other columns work correctly except the recipients column. I assume this is because that list is an array and needs to be expanded, unlike the other columns. So my question is, how do I take the results of recipients and expand it to my datagrid? As I mentioned above.
    Monday, May 27, 2019 4:45 PM
  • Hi,

    Do you want to check all message tracking logs on all your servers? If so, you can use command below directly:

    Get-TransportService | Get-MessageTrackingLog | select Timestamp, MessageId, TotalBytes, Directionality, ConnectorId, RecipientCount, EventID, Source, Sender, Recipients, MessageSubject | Export-Csv c:/temp/123.csv -NoTypeInformation

    It will export all logs for you, when you open it with "Excel", it will be the format of grid:

    Our forum isn't force on grammar, we mainly force on EMS tool itself. If my understanding is wrong, you can post it in Exchange development forum or script center forum which are very good at grammar. 

    Regards,

    Kyle Xu


    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.

    Tuesday, May 28, 2019 2:04 AM
    Moderator
  • I am aware I can export to Excel, that is not what I am looking for here. I need to output my results to a datagridview, which is why I'm asking about expanding the "Recipients" value in the cmdlet.
    Tuesday, May 28, 2019 12:36 PM
  • I am aware I can export to Excel, that is not what I am looking for here. I need to output my results to a datagridview, which is why I'm asking about expanding the "Recipients" value in the cmdlet.

    We mainly force on EMS tool itself, we don't familiar with PowerShell syntax. I would suggest you post it in Exchange development forum or script center forum which are mainly force on grammar. A suitable forum will be helpful to solve your confusion.

    Regards,

    Kyle Xu


    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, May 30, 2019 9:03 AM
    Moderator