Exports Microsoft Teams and their channels to an Excel file, excluding the 'General' channel, and includes the type of each team and channel.

This function connects to Microsoft 365 to fetch details of Microsoft Teams and their channels, then exports those details to an Excel file, excluding the 'General' channel. The exported details include Team Name, Team Description, Team Type, Channel Names with count numbers, and Channel Types.

The full path to the Excel workbook where the Teams and Channels details will be exported, including the workbook name with an extension of .xlsx.

The URL of the SharePoint Online admin center.

Export-CT365ProdTeamsToExcel -FilePath 'C:\Exports\Teams.xlsx' -AdminUrl ''
This example exports Teams and their channels (excluding 'General') to an Excel file named 'Teams.xlsx' located at 'C:\Exports'.

This function requires the PnP.PowerShell, ImportExcel, and PSFramework modules to be installed.
The user executing this function should have the necessary permissions to read Teams and Channels details from Microsoft 365.

[PnP PowerShell](
[ImportExcel Module](


function Export-CT365ProdTeamsToExcel {
    param (
        [Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)]
            switch ($psitem){
                {-not(([System.IO.Path]::GetExtension($psitem)) -match "(.xlsx)")}{
                    "Invalid file format: '$PSitem'. Use .xlsx"

                if ($_ -match '^[a-zA-Z0-9]+\.sharepoint\.[a-zA-Z0-9]+$') {
                else {
                    throw "The URL $_ does not match the required format."

    begin {
        Import-Module PnP.PowerShell, ImportExcel, PSFramework
        Write-PSFMessage -Level Host -Message "Preparing to export to $(Split-Path -Path $FilePath -Leaf)"

    process {
        try {
            $connectPnPOnlineSplat = @{
                Url = $AdminUrl
                Interactive = $true
                ErrorAction = 'Stop'
            Connect-PnPOnline @connectPnPOnlineSplat
            Write-PSFMessage -Level Verbose -Message "Connected to SharePoint Online"

            # Fetch all teams
            $teams = Get-PnPTeamsTeam
            Write-PSFMessage -Level Verbose -Message "Retrieved Microsoft Teams information"

            # Create an array to hold team and channel information
            $exportData = @()

            foreach ($team in $teams) {
                # Fetch channels for the team, excluding 'General'
                $channels = Get-PnPTeamsChannel -Team $team.DisplayName | Where-Object { $_.DisplayName -ne 'General' }

                $teamObject = [PSCustomObject]@{
                    "TeamName" = $team.DisplayName
                    "TeamDescription" = $team.Description
                    "TeamType" = $team.Visibility

                $channelCount = 1
                foreach ($channel in $channels) {
                    $channelPropertyName = "Channel${channelCount}Name"
                    $channelTypePropertyName = "Channel${channelCount}Type"
                    $teamObject | Add-Member -NotePropertyName $channelPropertyName -NotePropertyValue $channel.DisplayName
                    $teamObject | Add-Member -NotePropertyName $channelTypePropertyName -NotePropertyValue $channel.MembershipType

                $exportData += $teamObject

            # Export data to Excel
            $exportData | Export-Excel -Path $FilePath -WorksheetName "Teams" -AutoSize
            Write-PSFMessage -Level Host -Message "Data exported to Excel successfully"

        } catch {
            Write-PSFMessage -Message "Failed to connect to SharePoint Online" -Level Error 
        } finally {
            # Disconnect the PnP session
            Write-PSFMessage -Level Verbose -Message "Disconnected from Microsoft 365"

    end {
        Write-PSFMessage -Level Host -Message "Export completed. Check the file at $FilePath for the Teams and Channels details."