1 min readGet Microsoft Teams details using PowerShell

1 min readGet Microsoft Teams details using PowerShell

In this blog, we shall check how to get the list of Teams created in
your Office 365 environment with its details using PowerShell

  • Type
  • Owner
  • No. of Channels
  • Channels list

New Script! To get Microsoft Teams detail with members, follow this
blog.

Prerequisities:
To run this script you need to have installed SharePoint Online PnP
module. You can get this from
here.

function Export-TeamsList
{   
     param (   
           $ExportPath
           )   
    process
    {
        Connect-PnPMicrosoftGraph -Scopes "Group.Read.All","User.ReadBasic.All"
        $accesstoken =Get-PnPAccessToken
        $group = Invoke-RestMethod -Headers @{Authorization = "Bearer $accesstoken"} -Uri  "https://graph.microsoft.com/beta/groups?`$filter=resourceProvisioningOptions/any(c:c+eq+`'Team`')" -Method Get
        $TeamsList = @()
        do
        {
            foreach($value in $group.value)
            {
             "Group Name: " + $value.displayName + " Group Type: " + $value.groupTypes
             $id= $value.id
             Try
             {
             $team = Invoke-RestMethod -Headers @{Authorization = "Bearer $accesstoken"} -Uri  https://graph.microsoft.com/beta/Groups/$id/channels -Method Get
             "Channel count for " + $value.displayName + " is " + $team.value.id.count
             }
             Catch
             {
             "Could not get channels for " + $value.displayName + ". " + $_.Exception.Message
             $team = $null
             }
             If($team.value.id.count -ge 1)
             {
             $Owner = Invoke-RestMethod -Headers @{Authorization = "Bearer $accesstoken"} -Uri  https://graph.microsoft.com/v1.0/Groups/$id/owners -Method Get
             $Teams = "" | Select "TeamsName","TeamType","Channelcount","ChannelName","Owners"
             $Teams.TeamsName = $value.displayname
             $Teams.TeamType = $value.visibility
             $Teams.ChannelCount = $team.value.id.count
             $Teams.ChannelName = $team.value.displayName -join ";"
             $Teams.Owners = $Owner.value.userPrincipalName -join ";"
             $TeamsList+= $Teams
             $Teams=$null
             }
             
            }
            if ($group.'@odata.nextLink' -eq $null )
            {
              break
            }
            else
            {
              $group = Invoke-RestMethod -Headers @{Authorization = "Bearer $accesstoken"} -Uri $group.'@odata.nextLink' -Method Get
            }
        }while($true);
        $TeamsList
        $TeamsList |Export-csv $ExportPath -NoTypeInformation
    }
}
Export-TeamsList -ExportPath "C:teamslist.csv"
        

Result

Migrate Everything to Microsoft 365

Exchange Online SharePoint Online OneDrive For Business Microsoft Teams Microsoft Planner Viva Engage (Yammer) Microsoft Bookings Microsoft Forms Power Automate Microsoft Power BI Exchange Online SharePoint Online OneDrive For Business Microsoft Teams Microsoft Planner Viva Engage (Yammer) Microsoft Bookings Microsoft Forms Power Automate Microsoft Power BI
  • No Data Loss
  • Zero Downtime
  • ISO-Certified Protection

Start your free 15-days trial today !


4.5 out of 5