Powershell script for o365 Usuage report

We are a hybrid Org with most user mailboxes in the cloud. I need to create a report of users receiving the largest email count.
I could log in to Office 365 admin portal > Reports > Usage. But I am trying to get the same report using powershell or at least the report of users receiving the largest email count.

Any ideas would be really appreciated.

I’ll take a stab at this one, and I think it can be done in a one liner.

Get-Mailbox -ResultSize Unlimited | Get-MailboxStatistics | Sort-Object ItemCount -Descending

You could do some more with this like pipe it into a quick “Select-Object” and only grab the name/username/itemcount or other information. You could also filter out the top ten with Select-Object by saying “-first 10”.

Let me know if this gets you pointed in the right direction.

Thanks Bryce.
Yes I could use that command, although running it against 50K users would throttle my connection.
The other option would be like using a REST API (https://msdn.microsoft.com/en-us/library/office/dn387058.aspx)
Any experience in this area?

You could try running the command that Bryce provided with -ResultSize X (where X is any size you want to test). That would limit the run length.

The link to the API is out of date (that particular one has been deprecated in favor of Microsoft Graph (link is provided at the page your link refers to). You will need an API access token which should be found in the Admin Center. You would use Invoke-WebRequest -URI $URI (where $URI = full Graph report URL ). The Graph documentation is pretty easy to follow.

Thanks Matt. I missed that.
I believe this is what I needed https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/reportroot_getemailactivityusercounts