I'm sure I'm missing something obvious, because I've not used MS Graph in PowerShell anymore, and instructions for doing that with TeamsGroupActivityREportV5.PS1 are light.
I'm getting a permissions error starting at line 164, which is the Invoke-RestMethod for the 90 day SharePoint site usage detail as well as for all the other calls after that.
I've created the Azure app. I've given it Group.Read.All, Reports.Read.All, User.Read.All, and GroupMember.Read.All, as well as admin consent for those in the tenant. I'm assuming there is some other obvious step in the app setup that I have missed.
I've updated lines 133 - 134 with the appropriate AppID, TenantID and AppSecret. If I change the app secret to be invalid, I get an error on line 147 which is the grabbing of the token.
First error with the correct data in lines 133 - 134
Checking Microsoft 365 Groups and Teams in the tenant: contoso.onmicrosoft.com
Invoke-RestMethod : The remote server returned an error: (403) Forbidden.
At C:\changed\TeamsGroupsActivityReportV5.PS1:164 char:17
- ... SPOUsage = (Invoke-RestMethod -Uri $SPOUsageReportsURI -Headers $Head ...
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
- FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
First error if the AppSecret is wrong:
Checking Microsoft 365 Groups and Teams in the tenant: contoso.onmicrosoft.com
Invoke-WebRequest : {"error":"invalid_client","error_description":"AADSTS7000215: Invalid client secret is provided.\r\nTrace ID: 7e4df9ab-aad3-4239-b36a-d64aad72f900\r\nCorrelation ID: e388d8ed-e34f-480a-a8f5-8085b82c65da\r\nTimestamp: 2021-05-11
18:46:33Z","error_codes":[7000215],"timestamp":"2021-05-11 18:46:33Z","trace_id":"7e4df9ab-aad3-4239-b36a-d64aad72f900","correlation_id":"e388d8ed-e34f-480a-a8f5-8085b82c65da","error_uri":"https://login.microsoftonline.com/error?code=7000215"}
At C:\changed\TeamsGroupsActivityReportV5.PS1:147 char:17
- ... enRequest = Invoke-WebRequest -Method Post -Uri $uri -ContentType "ap ...
-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
- FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand