Deploy / Provision

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.

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

Source 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

Keep exploring