0

I have a powershell script running the following line of code:

$results = Get-MessageTrace -SenderAddress $senderEmail -StartDate $daysAgo -EndDate $todayDate

A new employee tries to run this and gets no results in the message trace. When we remove the -StartDate and -EndDate parameters shown below, it does get the expected results.

$results = Get-MessageTrace -SenderAddress $senderEmail

I would have expected the line with -StartDate and -EndDate to produce the same results as 3 other users, but when the problem user runs it, he gets zero results. Is there some sort of nuance to Get-MessageTrace?

I have had the user run it on my computer and it works. I have run the script on their computer and it failed, so that leads me to believe it is something with the local computer. We are running the script in VS Code. ExchangeOnlineManagement is installed and ExchangePowerShell also. I feel like I'm overlooking something.

mklement0
  • 382,024
  • 64
  • 607
  • 775
FloorPills
  • 21
  • 3
  • The format of the Date can be different for each user. Output date using Write-Host to check format. – jdweng Dec 20 '22 at 17:19
  • We edited the Get-Date and added -AsUTC. It looks like the reason it wasn't pulling the emails was it was getting the date as our timezone. It's weird that the script worked fine for me. Is there some setting within PS regarding the time zone? – FloorPills Dec 20 '22 at 17:31
  • 1
    Powershell has custom formats that are not documented very well. See following for a start : https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_powershell_config?force_isolation=true&view=powershell-7.3 – jdweng Dec 20 '22 at 17:41

1 Answers1

1

The -EndDate parameter was fed a date from Get-Date. Changing it to Get-Date -AsUTC worked.

The emails were apparently just outside the regular time zone and that was the reason they did not show up in the message trace.

mklement0
  • 382,024
  • 64
  • 607
  • 775
FloorPills
  • 21
  • 3