PeterJNGL The script is designed to run at least once and stop when there are no more pages to scan.
The first loop will run the query without any kind of evaluation and produce one of two possibilities:
- mailTrafficData == 5000: there is a possibility that we have more pages, so we iterate at least one more time
- mailTrafficData < 5000: this indicates that no more pages are left, so we exit the loop
Note that there is no case where mailTrafficData > 5000, as 5000 is the max PageSize we can set.
Let's say we have 5 pages, the first 4 with 5000 items each and the last page with 1000 items. The script would iterate through each page, as the first 4 evaluate to 5000. On the final page, mailTrafficData will evaluate to 1000, exiting the loop.
You can refer to our documentation here for more details on the underlying cmdlet used: Get-MailTrafficTopReport (ExchangePowerShell) | Microsoft Docs