Add a SharePoint Document Library as a Tab in Microsoft Teams
This script allows you to add a SharePoint Document Library as a Tab in Microsoft Teams.
Summary
Adding a SharePoint document library as a tab in Microsoft Teams is a common requirement for collaboration scenarios. While Teams provides an out-of-the-box (OOTB) experience for this, automating the process via PowerShell or Microsoft Graph can be tricky due to limitations.
Thanks to Tiago Duarte through the discussion within the [[BUG] Add-PnPTeamsTab with DocumentLibrary type creates a hidden tab(https://github.com/pnp/powershell/issues/4948) he raised , he found out a solution for it using Ms Graph PowerShell and I attempted to achieve same using PnP PowerShell.
# Connect to SharePoint Online admin center
Connect-PnPOnline -Url $AdminCenterURL -Interactive
$siteUrl = "https://contoso.sharepoint.com/sites/Retail"
$lib = "test" # Specify the library name
$team = "Retail"
$channel = "General"
$displayName = "test"
$ContentUrl = ($siteUrl + '/_layouts/15/filebrowser.aspx?app=teamsfile&scenario=teamsPage&auth=none&fileBrowser=' + [System.Web.HttpUtility]::UrlEncode('{"sdk":"1.0","entry":{"sharePoint":{"byPath":{"folder":"' + $siteUrl + '/' + $lib + '"}}}}') + '&theme={theme}')
Add-PnPTeamsTab -Team $team -Channel $channel -DisplayName $displayName -Type Custom -ContentUrl $ContentUrl -TeamsAppId "2a527703-1f6f-4559-a332-d8a7d288cd88"
# Disconnect SharePoint online connection
Disconnect-PnPOnline
$siteUrl = "https://contoso.sharepoint.com/sites/Retail"
$lib = "test" # Specify the library name
$team = "Retail"
$channel = "General"
$displayName = "test"
# Login to Microsoft 365 CLI with service principal
m365 login --appId "xxx" --tenant "xxx"
# Get teamId using CLI
$teamId = m365 teams team get --name $team --output json | ConvertFrom-Json | Select-Object -ExpandProperty id
# Get channelId using CLI
$channelId = m365 teams channel get --teamId $teamId --name $channel --output json | ConvertFrom-Json | Select-Object -ExpandProperty id
$ContentUrl = ($siteUrl + '/_layouts/15/filebrowser.aspx?app=teamsfile&scenario=teamsPage&auth=none&fileBrowser=' + [System.Web.HttpUtility]::UrlEncode('{"sdk":"1.0","entry":{"sharePoint":{"byPath":{"folder":"' + $siteUrl + '/' + $lib + '"}}}}') + '&theme={theme}')
m365 teams tab add --teamId $teamId --channelId $channelId --appId "2a527703-1f6f-4559-a332-d8a7d288cd88" --appName $displayName --contentUrl $ContentUrl
# Disconnect M365 connection
m365 logoutSource Credit
Sample first appeared on How to Add a SharePoint Document Library as a Tab in Microsoft Teams with PowerShell
Contributors
| Author(s) |
|---|
| Reshmee Auckloo |
Disclaimer
THESE SAMPLES ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
Tool documentation & references
- Want to learn more about PnP PowerShell and the cmdlets
Check out the PnP PowerShell site to get started and for the reference to the cmdlets.
- Want to learn more about CLI for Microsoft 365 and the commands
Check out the CLI for Microsoft 365 site to get started and for the reference to the commands.