Search code examples
powershellexchange-online

Get-message trace output not displaying


When using get message trace, It doesn't display the result (just a blank space), it works for any other days I select, apart from this one - I have checked and can confirm there is only one message to display, so the count should be 1.

The image below of the output enter image description here

see the code I am using below

$inboundMessages = Get-MessageTrace -Start $objStartDTcount1 -End $objEndDTcount1 -RecipientAddress $mailbox

# Count the number of inbound messages
$inboundMessageCount = $inboundMessages.Count

$inboundMessageCount

Any advice would be much appreciated.

I have tried using an already working code, with a different date and the results are fine, but if I change it to the day I want that returns a blank result as well.

The day I am looking to get info from is a Sunday

Using ($inboundMessages) returns the output to show there is an email there, its just the count thats not display the number 1

update if I use, $inboundMessages | measure-object, I get (below) enter image description here


Solution

  • Here is how I fixed the below,

    If anyone has a better/tidier solution, I would appreciate it.

    Instead of using .Count use | measure-object | Select-Object -expand Count

    It looks to seem that .count is not always accurate.

    for example

    $inboundMessages = Get-MessageTrace -Start $objStartDTcount1 -End $objEndDTcount1 -RecipientAddress $mailbox
    
    # Count the number of inbound messages
    $inboundMessageCount = $inboundMessages| measure-object | Select-Object -expand Count
    
    $inboundMessageCount