Skip to content

Submit new script to add doc lib as tab in Teams #867

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
72 changes: 72 additions & 0 deletions scripts/teams-add-sharepointlibrary-as-tab/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# 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](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.

# [PnP PowerShell](#tab/pnpps)

```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
```

[!INCLUDE [More about PnP PowerShell](../../docfx/includes/MORE-PNPPS.md)]

# [CLI for Microsoft 365](#tab/cli-m365-ps)

```powershell

$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 logout
```

[!INCLUDE [More about CLI for Microsoft 365](../../docfx/includes/MORE-CLIM365.md)]

***

## Source Credit

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//)

## 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/teams-add-sharepointlibrary-as-tab" 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.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
71 changes: 71 additions & 0 deletions scripts/teams-add-sharepointlibrary-as-tab/assets/sample.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
[
{
"schema": null,
"name": "teams-add-sharepointlibrary-as-tab",
"version": null,
"source": "pnp",
"title": "Add a SharePoint Document Library as a Tab in Microsoft Teams",
"url": "https://pnp.github.io/script-samples/teams-add-sharepointlibrary-as-tab/README.html",
"creationDateTime": "2021-03-20",
"updateDateTime": "2023-05-23",
"shortDescription": "This script allows you to add a SharePoint Document Library as a Tab in Microsoft Teams.",
"longDescription": null,
"products": [
"Teams"
],
"categories": [
"Deploy",
"Provision"
],
"tags": [
"Microsoft Teams",
"Governance",
"Connect-PnPOnline",
"Add-PnPTeamsTab",
"m365 login",
"m365 teams team get",
"m365 teams channel get",
"m365 teams tab add",
"m365 logout"
],
"metadata": [
{
"key": "PNP-POWERSHELL",
"value": "3.1.106"
},
{
"key":"CLI-FOR-MICROSOFT365",
"value":"10.10.0"
}
],
"thumbnails": [
{
"type": "image",
"order": 100,
"url": "https://raw.githubusercontent.com/pnp/script-samples/main/scripts/teams-add-sharepointlibrary-as-tab/assets/preview.png",
"alt": "preview image for the sample",
"slides": null
}
],
"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"
},
{
"name": "Want to learn more about CLI for Microsoft 365 and the commands",
"description": "Check out the CLI for Microsoft 365 site to get started and for the reference to the commands.",
"url": "https://aka.ms/cli-m365"
}
]
}
]