Microsoft 365 governance PowerShell script: What are my teams with private channels January 17, 2023 By: Syskit team 3 min read A PowerShell script for Microsoft 365 which finds you a list of teams that have private channels and list all their owners and members. If you are trying to find a list of all your teams with private channels then this PowerShell script is just what you need. The script’s purpose is to find all teams with private channels. It gets all teams and checks all the channels for each one. The script will output the team and any of the private channels it has, including all owners and members of the channel. By default, the script outputs the result only to the screen. There are optional flags available to export the result to CSV -ExportCSV (if set, this will automatically export the result to a CSV file. If no export path is set, it will export the file to %temp% folder) Example: Get-TeamsWithPrivateChannels.ps1 -ExportCSV -ExportFilePath Example: Get-TeamsWithPrivateChannels.ps1 -ExportCSV -ExportFilePath “C:Tempreport.csv” PowerShell Script code: #Owners, Members, channeldid and csv export) # Set script parameters [CmdletBinding()] param ( [switch]$ExportCSV, [string]$ExportFilePath = "$env:TEMP\$(Get-Date -Format "yyyy_MM_dd")TeamsWithPrivateChannels.csv" ) # Check or install Microsoft Teams module if ($null -eq (Get-Module -ListAvailable MicrosoftTeams)) { try { Write-Output "Microsoft Teams module not found. Trying to install" [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force | Out-Null Install-Module MicrosoftTeams -Force | Out-Null Write-Output "Microsoft Teams module installed" } catch { Write-Output "Unable to install Microsoft Teams module. $($Error[0].Exception.Message)" Return } } # Connect to Microsoft Teams try { Write-Output "Connecting to Microsoft Teams" Connect-MicrosoftTeams | Out-Null } catch { Write-Output "Unable to connect to Microsoft Teams. $($Error[0].Exception.Message)" Return } # Get all teams $AllTeams = Get-Team # Create empty report object $FinalReport = @() # Check channels of each team ForEach ($SingleTeam in $AllTeams) { # Get all private channels try { $AllChannels = $null $AllChannels = Get-TeamChannel -GroupId $SingleTeam.GroupId -MembershipType Private if ($AllChannels) { ForEach ($SingleChannel in $AllChannels) { # Get members of each channel $AllChannelMembers = Get-TeamChannelUser -GroupId $SingleTeam.GroupId -DisplayName $SingleChannel.DisplayName $TeamObject = [PSCustomObject]@{ Team = $SingleTeam.DisplayName ChannelName = $SingleChannel.DisplayName ChannelId = $SingleChannel.Id MembershipType = $SingleChannel.MembershipType Owners = ($AllChannelMembers | Where-Object { $_.Role -eq 'Owner' } | Select-Object -ExpandProperty Name) -join ',' Members = ($AllChannelMembers | Where-Object { $_.Role -eq 'Member' } | Select-Object -ExpandProperty Name) -join ',' } $FinalReport += $TeamObject } } } catch { Write-Output "Failed to get private channels of $($SingleTeam.DisplayName) team. $($Error[0].Exception.Message)" $TeamObject = [PSCustomObject]@{ Team = $SingleTeam.DisplayName Error = "Failed to get channels of the team. $($Error[0].Exception.Message)" } $FinalReport += $TeamObject } } # Print result to the screen Write-Output $FinalReport | Sort-Object User | Format-Table # Export result to CSV file if needed if ($ExportCSV) { $FinalReport | Sort-Object User | Export-Csv -Path $ExportFilePath -NoTypeInformation Write-Output "Report saved to $ExportFilePath" } # Stop before closing powershell window Read-Host "Script completed. Press 'Enter' to finish" Get a list of teams with private channels quickly with Syskit Point Syskit Point a Microsoft 365 governance and management platform, can get you a list of teams with private channels quickly. Syskit Point can generate various reports in real time. You can easily access them online and share them with your colleagues or managers with a simple link. Additionally, you can schedule reports, export them in excel or PDF, and perform management actions directly from a report. Easily check Project Server sites, security and database information, operational policies, time and task management settings, the projects list, and project permissions. Discover, secure, and control M365 Manage your company’s Microsoft 365 ecosystem with Syskit Point, a scalable platform that will help you govern and secure your environment while giving you deep visibility into your entire inventory. Try for free Related Posts Microsoft 365 governance Office 365 retention policies and labels Both are applied to resources using label policies. In Microsoft 365, we use re… June 8, 2021 10 min read Microsoft 365 governance Self-service provisioning in Microsoft 365 – Yes or no? Choosing between self-service and creation control means choosing between democ… July 28, 2021 7 min read Microsoft 365 governance Taming Office 365 governance and reporting in enterprise SaaS solutions Different departments across businesses claim ownership over various resources.… May 28, 2021 15 min read