Wouldn’t it be cool to get that report through PowerShell/Graph API?

In the Microsoft Teams admin portal you have several interesting reports. You can run the reports and download as a csv. Then after import downloading, you could import the csv into PowerShell to play with the data. Wouldnt it be better to get these data directly into PowerShell? What if you want only a portion of the data, or want any of the others reports there?

You can get lots of these data with some clever Graph API calls, but that is a lot of work putting together. Since there are other reports available directly from the Graph API, i thought that these admin portal reports most probably were loaded also through the Graph API.

Here comes the browsers developer mode in use, which is a great tool for fiddling around or debugging. In my case i use the Edge Chromium browser.
Go to https://admin.teams.microsoft.com/analytics/reports. Now you need to open the developer mode by pressing CTRL+Shift+I.

It will look like this:

Press the network tab, and click Clear(the button next to the red dot).
Select the preferred report and date range, then press run report.
Look at the developer window, this is where the magic is happening. You are basically looking at all the request/calls that is happening in the background.

Now you click on the one that is named ‘summary-timeseries….’. Well, what do we have here?

We have a request URL and it says its a GET method. That looks like a rest call. The URL though does not look like he familiar graph.microsoft.com URL. My thought is that this is some kind of internal API URL that is really meant to be public. If we look further down on the page, we see a property called ‘authorization’. This look really familiar if you have looked at the token/header you use for doing Graph API calls in PowerShell. If this is new to you, take a look at my ‘Getting started with Graph API and PowerShell’ post. Copy the request URL and the authorization token, and open your favorite PowerShell editor and put it were appropriate in this little script snippet.

$url = 'https://tas.teams.microsoft.com/v2/teams/summary-timeseries?timeperiod=last-ninety-days&includeTimeSeries=ActiveUsers&metrics=all&pagesize=20&nextCursor=null'
$Header = @{"Authorization" = "Bearer $token" }
$data = Invoke-RestMethod Uri $url Method GET Headers $Header ContentType 'application/json'

Now, take a look at whats inside the $data variable.

Now its up to you to play around and see if there is any use for this in your case. I guess its not the most practical way to get a token, but at least its fun to play around.

One thought on “Wouldn’t it be cool to get that report through PowerShell/Graph API?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s