Locate all Teams having a Wiki and export the list to CSV
Locate all Teams having a Wiki and export the list to CSV
Summary
Locate all Teams having a Wiki and export the list to CSV
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
Contributors
| Author(s) |
|---|
| Valeras Narbutas |
Disclaimer
THESE SAMPLES ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
Tool documentation & references
- Want to learn more about CLI for Microsoft 365 and the commands
Check out the CLI for Microsoft 365 site to get started and for the reference to the commands.
- Want to learn more about Microsoft Graph PowerShell SDK and the cmdlets
Check out the Microsoft Graph PowerShell SDK documentation site to get started and for the reference to the cmdlets.