Entra / Microsoft 365 · Teams
Find Teams channels with website tabs
Find Teams channel tabs that point to external websites across all teams in the tenant.
Connect & set up
Run these once per session. All scopes are read-only unless the script makes changes.
Connect-MgGraph -NoWelcome -Scopes Directory.Read.All, Team.ReadBasic.All, TeamSettings.Read.All, ChannelSettings.Read.All, TeamsTab.Read.All
Run it
The main script. Copy it, or download the .ps1 and run it from your console.
Connect-MgGraph -NoWelcome `-Scopes Directory.Read.All, Team.ReadBasic.All, TeamSettings.Read.All, ChannelSettings.Read.All, TeamsTab.Read.AllWrite-Host "Finding Teams"[array]$Teams = Get-MgGroup -Filter "resourceProvisioningOptions/Any(x:x eq 'Team')" -All | Sort-Object DisplayNameIf (!($Teams)) {Write-Host "For some reason, I can't find any Teams... exiting..."; break }$CSVOutputFile = "c:\temp\WebSitesinTeamsChannels.CSV"# Clear-HostWrite-Host ("Processing {0} teams to check for tabs containing websites" -f $Teams.count)$Report = [System.Collections.Generic.List[Object]]::new() # Create output file for report$i = 0# Loop through each team to examine its channels, tabs, and appsForEach ($Team in $Teams) {$i++$ProgressBar = "Processing Team " + $Team.DisplayName + " (" + $i + " of " + $Teams.Count + ")"If ($TeamDetails.IsArchived -ne $True) { # Team is not archived, so we can fetch informationWrite-Progress -Activity "Checking Teams Information" -Status $ProgressBar -PercentComplete ($i/$Teams.Count*100)# Get Team owners[array]$Owners = Get-MgGroupOwner -GroupId $Team.Id$TeamOwners = $Owners.AdditionalProperties.displayName -Join ", "[array]$TeamChannels = Get-MgTeamChannel -TeamId $Team.Id -ErrorAction SilentlyContinueForEach ($Channel in $TeamChannels) {[array]$Tabs = Get-MgTeamChannelTab -ChannelId $Channel.Id -TeamId $Team.Id -ExpandProperty TeamsApp -ErrorAction SilentlyContinueIf ($Tabs) {# Debug line - uncomment it to see the channelid details as they are processed# Write-Host ("Processing tab {0} in channel {1} of team {2}" -f $Tab.DisplayName, $Channel.DisplayName, $Team.DisplayName)ForEach ($Tab in $Tabs) {$WebSiteURL = $nullIf ($Tab.TeamsApp.Id -eq "com.microsoft.teamspace.tab.web") {If ($Tab.WebURL) {$StartPosition = $Tab.WebURL.IndexOf("webUrl=") + 7# Some website tabs have &Label and some have ?Label, so we check for both$LabelPosition = $Tab.WebURL.IndexOf("&label")If ($LabelPosition -eq -1) {$LabelPosition = $Tab.WebURL.IndexOf("?label")}$URLLength = ($LabelPosition - ($StartPosition))$WebSite = $Tab.WebURL.SubString($StartPosition, $URLLength)$WebSiteURL = [System.Web.HttpUtility]::UrlDecode($WebSite)} Else {$WebSiteURL = "Can't find web site URL"}$ReportLine = [PSCustomObject][Ordered]@{Team = $Team.DisplayNameChannel = $Channel.DisplayName"Tab name" = $Tab.DisplayNameURL = $WebSiteURL'Team owners' = $TeamOwnersTeamId = $Team.IdAppId = $Tab.TeamsApp.Id}$Report.Add($ReportLine)}} #End ForEach TabStart-Sleep -Milliseconds 250 # Brief pause before next channel} #End if Tabs} #End ForEach channel} Else { # End Archive checkWrite-Host ("The {0} team is archived - no check done" -f $Team.DisplayName)}Start-Sleep -Milliseconds 100} #End ForEach Team$Report | Out-GridView$Report | Export-CSV -NoTypeInformation $CSVOutputFile -Encoding UTF8 -Delimiter ";"Write-Host ("All done. {0} Teams processed. A website tab was found in {1} channels. CSV file generated in {2}" -f $Teams.count, $Report.count, $CSVOutputFile)
Attribution
Author
Office365itpros