Home Get teams tabs and export to CSV
Post
Cancel

Get teams tabs and export to CSV

Summary

This script will locate all Teams having a Wiki and export the list to CSV

Pre-requisites

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
Connect-MgGraph -Scopes "Team.ReadBasic.All", "TeamSettings.Read.All", "TeamSettings.ReadWrite.All", "User.Read.All", "Directory.Read.All", "User.ReadWrite.All", "Directory.ReadWrite.All", "Channel.ReadBasic.All", "TeamsTab.Read.All"
$accessToken = m365 util accesstoken get --resource https://graph.microsoft.com --new
$accessToken.Trim('"');


$header = @{
    'Authorization' = "Bearer $($accessToken.Trim('"'))"
   'Content-type'  = "application/json"
}

$teams = (Invoke-MgGraphRequest -Method GET https://graph.microsoft.com/v1.0/me/joinedTeams -Headers $header).value

$teamsWithWiki = @()
foreach($team in $teams)
{
    
    $channels = (Invoke-MgGraphRequest -Method GET https://graph.microsoft.com/v1.0/teams/$($team.id)/channels -Headers $header).value
    foreach($channel in $channels){
        
        $tabs = (Invoke-MgGraphRequest -Method GET https://graph.microsoft.com/v1.0/teams/$($team.id)/channels/$($channel.id)/tabs -Headers $header).value
        # $tabs = (Invoke-RestMethod -Uri "https://graph.microsoft.com/v1.0/teams/$($team.id)/channels/$($channel)/tabs" -Headers $header).value
        if ($tabs.displayName -match "Wiki")
        {
            $teamsWithWiki += $team
        }
    }
}

# Export results to CSV file
$teamsWithWiki.GetEnumerator() | select description, id, displayName, tenatId  | Export-Csv -Path "teams_with_wiki.csv" -NoTypeInformation


PNP Script sample site

Script sample site

This post is licensed under CC BY 4.0 by the author.

Tip of the day. Display multilanguage content

SharingIsCaring. Create test users with Microsoft Graph API and Chat GPT