Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions scripts/spo-get-team-channel-hub-from-siteurl/README.md
Original file line number Diff line number Diff line change
@@ -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)]
<img src="https://m365-visitor-stats.azurewebsites.net/script-samples/scripts/spo-get-team-channel-hub-from-siteurl" aria-hidden="true" />
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
58 changes: 58 additions & 0 deletions scripts/spo-get-team-channel-hub-from-siteurl/assets/sample.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}
]