Use Microsoft Graph API with PowerShell – Part 3

You read the third part of this series, do a lot of examples. This should help you to build your own Requests as you need them.

Part 1 – Authentication and Azure App – Use Microsoft Graph API with PowerShell – Part 1 » TechGuy
Part 2 – Oauth2.0 – Use Microsoft Graph API with PowerShell – Part 2 » TechGuy
Part 3 – First Powershell Script to get a Teams Lis and Walkthrough – Use Microsoft Graph API with PowerShell – Part 3 » TechGuy
Part 4 – many examples – Use Microsoft Graph API with PowerShell – Part 4 » TechGuy

Ok, this Post will take for granted that you have gone through Part 1 and Part 2 and successfully authenticated. To better understand, we build the first Query/Request to get an idea of how I am trying to archive a Customer Request.


The Request

The Result should show us a complete List of all Microsoft Teams and their Details, using PowerShell and Microsoft GRAPH API.

The First Steps

As we know how to authenticate and build the Azure App, we can focus on the correct URAL and Parameters to query the GRAPH API.

First Start in Microsoft Graph REST API v1.0 reference – Microsoft Graph v1.0 | Microsoft Docs where you get the complete list of References/Commands/Requests you can archive with Microsoft GRAPH API.

Searching the Link from above leads us to the “Get a list of Groups” Query. At the moment, there is no dedicated TEAMS Query to archive this.

But what you can see here List groups – Microsoft Graph beta | Microsoft Docs that always on top you see the necessary Permission for your Azure App (see Part 1)

So make sure your Azure App has been configured appropriately.

So Documentation is telling us we should use the following Query.

Now, we can build our Script.

PowerShell Script to Get all Teams

As i said at the beginning, Authentication an Token is a prerequisite for this, so this code only shows the Microsoft GRAPH API Query and the Result.

$headers = @{
        "Authorization" = "Bearer $($tokenResponse.access_token)"
        "Content-type"  = "application/json"
    }

$URL = "https://graph.microsoft.com/beta/groups?`$filter=resourceProvisioningOptions/Any(x:x eq 'Team')"  
$AllTeams = Invoke-RestMethod -Headers $headers -Uri $URL -Method GET

The Result looks like this.

Now let’s take a closer look into “value”

$AllTeams.value

Now we get a list of all our Teams with some Details.

Result

We have accomplished the Request and received the whole Teams List with PowerShell and Microsoft GRAPH API.

Stay tuned for Part 4, which will include many examples and how to build the Queries and Bodies.

Michael Seidl

8 thoughts on “Use Microsoft Graph API with PowerShell – Part 3”

  1. Pingback: Use Microsoft Graph API with PowerShell – Part 1 » TechGuy

  2. Pingback: Use Microsoft Graph API with PowerShell – Part 4 » TechGuy

  3. Pingback: Paging in Microsoft Graph REST API » TechGuy

  4. Pingback: Send Mail with PowerShell and Microsoft Graph API » TechGuy

  5. Pingback: Assign Windows 365 License with PowerShell and MS GRAPH API » TechGuy

  6. Pingback: Enable Lost Mode for Intune Device with PowerShell and Microsoft Graph API - TechGuy

  7. Pingback: Create Microsoft Team with PowerShell and MS Graph API - TechGuy

  8. Pingback: Draft Mail with PowerShell and Microsoft Graph API - TechGuy

Leave a Comment

Your email address will not be published. Required fields are marked *

*