Closed heimdal-31 closed 3 years ago
I did read the closed issue 28 and added AccessReview.ReadWrite.All and AccessReview.ReadWrite.Membership. I'm still seeing a 403 forbidden error on line 164, which is
$SPOUsage = (Invoke-RestMethod -Uri $SPOUsageReportsURI -Headers $Headers -Method Get -ContentType "application/json") -Replace "...Report Refresh Date", "Report Refresh Date" | ConvertFrom-Csv
So, my complete list of permissions is:
By any chance is this a test tenant? If it is, there might not be any report data to fetch. I've met that issue before.
5 year old tenant with 1200 users. I was trying to run the script because I'd stumbled across a Team with three users, two of whom no longer work for the company, with last activity in 2018. I'm trying to figure out how many dead Teams we have out there.
The error looks as if the Reports.Read.All permission isn't assigned. It's the Reports API which is used to grab the SPO usage data for the tenant and if you don't have access to it...
I agree. That does seem to be the issue. That permission is granted and administratively approved.
Can you point me at any further steps on the Azure side to figure out what is going on? My successful grabbing of the token and then the 403 does not show up in the Azure logs for the application.
Unfortunately, your response confirms what I expect. I've done something non-obvious with the Azure app setup that is causing an issue.
You're using delegated permissions. I use application permissions. Try using an application consent for Reports.Read.All
Thank you! As I wrote at the beginning, this is the first time I've used MS Graph in PowerShell.
Changing those grants to Application permissions was the answer. I have results now.
Thanks for your response and for the incredibly useful too.
The code posted here is to help people develop their own solutions. To do that, you've got to get past my horrible code. But I am glad that it worked out in the end.
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
First error if the AppSecret is wrong: