Error while fetching MessageTrace data using PowerShell

%3CLINGO-SUB%20id%3D%22lingo-sub-1173395%22%20slang%3D%22en-US%22%3EError%20while%20fetching%20MessageTrace%20data%20using%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1173395%22%20slang%3D%22en-US%22%3E%3CP%3EI%20tried%20to%20fetch%20the%20Message%20Trace%20data%20for%20the%20last%207%20days%20through%20Power%20Shell.%20After%20getting%203%20days%20of%20data%2C%20we%20face%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3ECmdlet-InvalidExpressionException.%20(Page%20result%20exceeds%20maximum%20threshold.%20CATEGORY%3A%20InvalidArgument.)%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWe%20tried%20to%20fetch%20the%20data%20multiple%20times%20but%20we%20keep%20facing%20the%20error.%20We%20couldn't%20fetch%20data%20for%20more%20than%20three%20days.%20We%20get%20approximately%201.4%20million%20records.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWe%20used%20the%20below%20script%20to%20fetch%20the%20data%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3E%24Page%20%3D%201%3Bdo%7B%24CurrMessages%20%3D%20Get-MessageTrace%20-PageSize%205000%20-Page%20%24Page%20-StartDate%20(Get-Date).addDays(-7)%20-EndDate%20(Get-Date)%3B%24Page%2B%2B%3B%24CurrMessages%7Duntil%20(%24CurrMessages%20-eq%20%24null)%3B%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1173395%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExchange%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EOffice%20365%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2391037%22%20slang%3D%22en-US%22%3ERe%3A%20Error%20while%20fetching%20MessageTrace%20data%20using%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2391037%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F169687%22%20target%3D%22_blank%22%3E%40bala%20official%3C%2FA%3E%26nbsp%3Btrying%20breaking%20the%20time%20into%20chunks.%3C%2FP%3E%3CP%3EThat%20is%20a%20big%20time%20frame%20for%20messages%20and%20you%20are%20going%20to%20exceed%20the%20page%20limits.%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22meddiesamuel_0-1622115576210.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F284265iB3A4134C7CCD4B01%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22meddiesamuel_0-1622115576210.png%22%20alt%3D%22meddiesamuel_0-1622115576210.png%22%20%2F%3E%3C%2FSPAN%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22meddiesamuel_1-1622115591483.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F284266iB4ECD45AD29E3971%2Fimage-size%2Fmedium%3Fv%3Dv2%26amp%3Bpx%3D400%22%20role%3D%22button%22%20title%3D%22meddiesamuel_1-1622115591483.png%22%20alt%3D%22meddiesamuel_1-1622115591483.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

I tried to fetch the Message Trace data for the last 7 days through Power Shell. After getting 3 days of data, we face 

 

Cmdlet-InvalidExpressionException. (Page result exceeds maximum threshold. CATEGORY: InvalidArgument.)

 

We tried to fetch the data multiple times but we keep facing the error. We couldn't fetch data for more than three days. We get approximately 1.4 million records.

 

We used the below script to fetch the data,

 

$Page = 1;do{$CurrMessages = Get-MessageTrace -PageSize 5000 -Page $Page -StartDate (Get-Date).addDays(-7) -EndDate (Get-Date);$Page++;$CurrMessages}until ($CurrMessages -eq $null);

 

 

1 Reply

@bala official trying breaking the time into chunks.

That is a big time frame for messages and you are going to exceed the page limits.

meddiesamuel_0-1622115576210.pngmeddiesamuel_1-1622115591483.png