diff --git a/scripts/spo-get-team-channel-hub-from-siteurl/README.md b/scripts/spo-get-team-channel-hub-from-siteurl/README.md new file mode 100644 index 000000000..2f6cb7e92 --- /dev/null +++ b/scripts/spo-get-team-channel-hub-from-siteurl/README.md @@ -0,0 +1,84 @@ + + +# Find Teams, Channels, Hub Site associated with a SharePoint site + +## Summary + +This script finds the associated Microsoft Teams and Channel associated with SharePoint site. It also retrieves the associated Hub Site Url information. The script reads site URLs from a CSV file, connects to each site, and determines whether the site is a teams site or a channel site. + + +![Example Screenshot](assets/preview.png) + +# [PnP PowerShell](#tab/pnpps) + +```powershell +cls + +# Connection variables +$invocation = (Get-Variable MyInvocation).Value +$directorypath = Split-Path $invocation.MyCommand.Path +$csvPath = Join-Path $directorypath 'Sites.csv' # CSV should have a column 'SiteUrl' +$clientId = 'xxxxxxxxxx' +$domain = 'contoso' +$adminSiteURL = "https://$domain.sharepoint.com" + +# Read sites from CSV +$sites = Import-Csv -Path $csvPath + +foreach ($s in $sites) { + $siteUrl = $s.SiteUrl + Write-Host "Connecting to site: $siteUrl" + + $siteconn = Connect-PnPOnline -Url $siteUrl -ClientId $clientId -ReturnConnection + $site = Get-PnPSite -Includes GroupId, RelatedGroupId, RootWeb.Title, HubSiteId -Connection $siteconn + + $TeamName = '' + $ChannelName = '' + $HubSiteId = '' + $HubSiteUrl = '' + + if ($site.GroupId -ne [Guid]::Empty) { + # Team root site + $TeamName = $site.RootWeb.Title + $ChannelName = 'General' + $HubSiteId = $siteInfo.HubSiteId + $HubSiteUrl = (HubSiteId.Guid | Get-PnPHubSite).SiteUrl + } + elseif ($site.RelatedGroupId) { + # Channel or connected site + $TeamName = (Get-PnPMicrosoft365Group -Identity $site.RelatedGroupId).DisplayName + $ChannelName = $site.RootWeb.Title -Replace "$TeamName-", '' + $HubSiteId = $siteInfo.HubSiteId + $HubSiteUrl = (HubSiteId.Guid | Get-PnPHubSite).SiteUrl + } + + # Add to results array + $results += [PSCustomObject]@{ + SiteUrl = $siteUrl + TeamName = $TeamName + ChannelName = $ChannelName + HubSiteId = $HubSiteId + HubSiteUrl = $HubSiteUrl + } +} + +$results | Export-Csv -Path ($directorypath + "\TeamsChannelsExport.csv") -NoTypeInformation -Encoding UTF8 +``` + +[!INCLUDE [More about PnP PowerShell](../../docfx/includes/MORE-PNPPS.md)] + +*** + +## Source Credit + +Sample first appeared on [Find Teams, Channels, Hub Site associated with a SharePoint URL](https://reshmeeauckloo.com/posts/powershell-getteamchannel-from-siteurl/) + +## Contributors + +| Author(s) | +|-----------| +| [Reshmee Auckloo](https://github.com/reshmee011) | + + +[!INCLUDE [DISCLAIMER](../../docfx/includes/DISCLAIMER.md)] + diff --git a/scripts/spo-get-team-channel-hub-from-siteurl/assets/Preview.png b/scripts/spo-get-team-channel-hub-from-siteurl/assets/Preview.png new file mode 100644 index 000000000..aa4daa696 Binary files /dev/null and b/scripts/spo-get-team-channel-hub-from-siteurl/assets/Preview.png differ diff --git a/scripts/spo-get-team-channel-hub-from-siteurl/assets/sample.json b/scripts/spo-get-team-channel-hub-from-siteurl/assets/sample.json new file mode 100644 index 000000000..1f8e16f52 --- /dev/null +++ b/scripts/spo-get-team-channel-hub-from-siteurl/assets/sample.json @@ -0,0 +1,58 @@ +[ + { + "name": "spo-get-team-channel-hub-from-siteurl", + "source": "pnp", + "title": "Find Teams and Channels associated with a SharePoint URL", + "shortDescription": "Find Teams and Channels associated with a SharePoint URL", + "url": "https://pnp.github.io/script-samples/spo-get-team-channel-hub-from-siteurl/README.html", + "longDescription": [ + "Sharing links can lead to oversharing, especially when default site sharing settings haven’t been updated to ‘People with existing access.’ To address this, consider using a utility script that deletes sharing links at the folder, file, and item levels. This approach can help mitigate oversharing issues during the Copilot for M365 rollout." + ], + "creationDateTime": "2026-06-20", + "updateDateTime": "2026-06-20", + "products": [ + "SharePoint", + "Teams", + "Channels" + ], + "metadata": [ + { + "key": "PNP-POWERSHELL", + "value": "3.2.0" + } + ], + "categories": [ + "Report" + ], + "tags": [ + "modern", + "Connect-PnPOnline", + "Get-PnPHubSite", + "Get-PnPMicrosoft365Group", + "Get-PnPSite" + ], + "thumbnails": [ + { + "type": "image", + "order": 100, + "url": "https://raw.githubusercontent.com/pnp/script-samples/main/scripts/spo-get-team-channel-hub-from-siteurl/assets/preview.png", + "alt": "" + } + ], + "authors": [ + { + "gitHubAccount": "reshmee011", + "company": "", + "pictureUrl": "https://avatars.githubusercontent.com/u/7693852?v=4", + "name": "Reshmee Auckloo" + } + ], + "references": [ + { + "name": "Want to learn more about PnP PowerShell and the cmdlets", + "description": "Check out the PnP PowerShell site to get started and for the reference to the cmdlets.", + "url": "https://aka.ms/pnp/powershell" + } + ] + } +]