|
| 1 | +# Add a SharePoint Document Library as a Tab in Microsoft Teams |
| 2 | + |
| 3 | +## Summary |
| 4 | + |
| 5 | +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. |
| 6 | + |
| 7 | +Thanks to [Tiago Duarte](https://github.com/tiagoduarte) 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. |
| 8 | + |
| 9 | +# [PnP PowerShell](#tab/pnpps) |
| 10 | + |
| 11 | +```powershell |
| 12 | +
|
| 13 | +# Connect to SharePoint Online admin center |
| 14 | +Connect-PnPOnline -Url $AdminCenterURL -Interactive |
| 15 | +
|
| 16 | +$siteUrl = "https://contoso.sharepoint.com/sites/Retail" |
| 17 | +$lib = "test" # Specify the library name |
| 18 | +$team = "Retail" |
| 19 | +$channel = "General" |
| 20 | +$displayName = "test" |
| 21 | +
|
| 22 | +$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}') |
| 23 | +Add-PnPTeamsTab -Team $team -Channel $channel -DisplayName $displayName -Type Custom -ContentUrl $ContentUrl -TeamsAppId "2a527703-1f6f-4559-a332-d8a7d288cd88" |
| 24 | +# Disconnect SharePoint online connection |
| 25 | +Disconnect-PnPOnline |
| 26 | +``` |
| 27 | + |
| 28 | +[!INCLUDE [More about PnP PowerShell](../../docfx/includes/MORE-PNPPS.md)] |
| 29 | + |
| 30 | +# [CLI for Microsoft 365](#tab/cli-m365-ps) |
| 31 | + |
| 32 | +```powershell |
| 33 | +
|
| 34 | +$siteUrl = "https://contoso.sharepoint.com/sites/Retail" |
| 35 | +$lib = "test" # Specify the library name |
| 36 | +$team = "Retail" |
| 37 | +$channel = "General" |
| 38 | +$displayName = "test" |
| 39 | +
|
| 40 | +# Login to Microsoft 365 CLI with service principal |
| 41 | +m365 login --appId "xxx" --tenant "xxx" |
| 42 | +
|
| 43 | +# Get teamId using CLI |
| 44 | +$teamId = m365 teams team get --name $team --output json | ConvertFrom-Json | Select-Object -ExpandProperty id |
| 45 | +# Get channelId using CLI |
| 46 | +$channelId = m365 teams channel get --teamId $teamId --name $channel --output json | ConvertFrom-Json | Select-Object -ExpandProperty id |
| 47 | +
|
| 48 | +$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}') |
| 49 | +
|
| 50 | +m365 teams tab add --teamId $teamId --channelId $channelId --appId "2a527703-1f6f-4559-a332-d8a7d288cd88" --appName $displayName --contentUrl $ContentUrl |
| 51 | +
|
| 52 | +# Disconnect M365 connection |
| 53 | +m365 logout |
| 54 | +``` |
| 55 | + |
| 56 | +[!INCLUDE [More about CLI for Microsoft 365](../../docfx/includes/MORE-CLIM365.md)] |
| 57 | + |
| 58 | +*** |
| 59 | + |
| 60 | +## Source Credit |
| 61 | + |
| 62 | +Sample first appeared on [How to Add a SharePoint Document Library as a Tab in Microsoft Teams with PowerShell](https://reshmeeauckloo.com/posts/powershell-teams-add-documentlibrary-as-tab//) |
| 63 | + |
| 64 | +## Contributors |
| 65 | + |
| 66 | +| Author(s) | |
| 67 | +|-----------| |
| 68 | +| [Reshmee Auckloo](https://github.com/reshmee011) | |
| 69 | + |
| 70 | + |
| 71 | +[!INCLUDE [DISCLAIMER](../../docfx/includes/DISCLAIMER.md)] |
| 72 | +<img src="https://m365-visitor-stats.azurewebsites.net/script-samples/scripts/teams-add-sharepointlibrary-as-tab" aria-hidden="true" /> |
0 commit comments