Forum Discussion
dmarquesgn
Dec 22, 2022Iron Contributor
Exchange Online email counting report
Hi, I'm trying to work on some monthly statistics for our company, where I could set a schedule task with powershell to get this data monthly. First of all, I would like to extract the total number ...
- Dec 22, 2022There's a built-in report that gives you this data: https://admin.microsoft.com/#/reportsUsage/EmailActivity
If you want to access it programmatically, use the Graph API: https://learn.microsoft.com/en-us/graph/api/reportroot-getemailactivityuserdetail?view=graph-rest-1.0
VasilMichev
Jan 04, 2023MVP
Yup, $ is a special character in PowerShell, so you have to escape it (add a ` in front):
"https://graph.microsoft.com/beta/reports/getEmailActivityCounts(period='D30')?`$format=application/json"
"https://graph.microsoft.com/beta/reports/getEmailActivityCounts(period='D30')?`$format=application/json"
dmarquesgn
Jan 05, 2023Iron Contributor
Hi, thanks. This worked like a charm. Now I've got the values on the JSON format.
How can I access the values on a specific field and count them all for example?
Thanks
- dmarquesgnJan 05, 2023Iron Contributor
Yes, I got the idea, so created this and solved it.
$TotalEmailCount = ($EmailActivityResponse.Content | ConvertFrom-Json).value.receive foreach ($receivedemailday in $TotalEmailCount) { $TotalEmails += $receivedemailday }Thanks for the guidance.
- VasilMichevJan 05, 2023MVPThe counts are already included, just reference them? I.e. to get the latest values:
($EmailActivityResponse.Content | ConvertFrom-Json).value[0].receive