#office 365 get-messagetrace

When we have huge number of users we will not get the required results as our environment would produce extremely huge number of results which spanned multiple pages. By default only 1000 items will be present in a page and only the first page will be displayed.

We can increase the number of items to be displayed to 5000, using the below command, still you might not get the required result if the output spans multiple pages.

https://blogs.technet.microsoft.com/eopfieldnotes/2014/12/16/message-trace-the-powershell-way/

 

Get-MessageTrace -StartDate $dateStart -EndDate $dateEnd -PageSize 5000 | Where {$_.Subject -like “*example*”} | ft -Wrap

with -page (vaule from 1-1000) can get search results up to 5000×1000 entries

$dateEnd = get-date

$dateStart = $dateEnd.AddHours(-10)

for($c=1;$c -lt 1001; $c++)

# For loop goes for 1000 iterations as Maximum number of pages there could be 1000

{

if((Get-MessageTrace -StartDate $dateStart -EndDate $dateEnd -PageSize 5000 -Page $c).count -gt 0)

{

Get-MessageTrace -StartDate $dateStart -EndDate $dateEnd -PageSize 5000 -Page $c | Where {$_.Subject -like “*example*”} | ft -Wrap

}

else

{break;}

}

https://blogs.technet.microsoft.com/praveenkumar/2015/08/12/message-tracking-by-subject/

 

|export-csv -append

export to csv file with append more than 5000 entries.