gscales/Exch-Rest

Get-EXREMailAppUsageAppsUserCounts

ISIITAdmin opened this issue · 3 comments

Hi,

Really loving this module,

However, I'm having some trouble running the cmdlet in the title.

I'm able to get a token that is using an App in Azure and my admin mailbox but whenever I run the cmdlet i get this error.

Is this something I am doing wrong?

PS C:\windows\system32> Get-EXREmailAppUsageAppsUserCounts | FT
https://graph.microsoft.com/v1.0/reports/getEmailAppUsageAppsUserCounts(period='D7')?$format=text/csv

Error making REST Get :
RequestURL : https://graph.microsoft.com/v1.0/reports/getEmailAppUsageAppsUserCounts(period='D7')?$format=text/csv
You cannot call a method on a null-valued expression.
At line:25 char:9

  •     $OutPutStream = $Output.ReadAsStreamAsync().Result
    
  •     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (:) [], RuntimeException
    • FullyQualifiedErrorId : InvokeMethodOnNull

You cannot call a method on a null-valued expression.
At line:26 char:16

  • ... return ConvertFrom-Csv ([System.Text.Encoding]::UTF8.GetString($ ...
  •             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (:) [], RuntimeException
    • FullyQualifiedErrorId : InvokeMethodOnNull

Are you getting a 403 error ? it looks to me like whatever your using for your application registration doesn't have the grants to be able to access the reporting operations. Its not just about being an administrator you need to have the report grants eg Reports.Read.All (and example if option 4 in the connection menu)

You can see from the Scopes in the Token you posted

scope : Calendar.ReadWrite Calendars.Read.Shared Calendars.ReadWrite Contacts.ReadWrite
DeviceManagementConfiguration.Read.All DeviceManagementConfiguration.ReadWrite.All
Directory.AccessAsUser.All Directory.Read.All Files.Read Files.Read.All Group.Read.All
Group.ReadWrite.All Mail.ReadWrite People.Read People.Read.All User.Read.All Users.Read

This it doesn't contain the Reports.Read.All Scope which is why the error message tells you

message": "Invalid scope claims/roles.",

You need to fix whatever application registration you using to include the scope for Reports.Read.All and then make sure you consent to the updated Grants