Skip to content

Commit 78286bc

Browse files
authored
Merge pull request #867 from reshmee011/add_doc_tab
Submit new script to add doc lib as tab in Teams
2 parents 0d13f9f + 330509b commit 78286bc

File tree

4 files changed

+143
-0
lines changed

4 files changed

+143
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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" />
328 KB
Loading
68.7 KB
Loading
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
[
2+
{
3+
"schema": null,
4+
"name": "teams-add-sharepointlibrary-as-tab",
5+
"version": null,
6+
"source": "pnp",
7+
"title": "Add a SharePoint Document Library as a Tab in Microsoft Teams",
8+
"url": "https://pnp.github.io/script-samples/teams-add-sharepointlibrary-as-tab/README.html",
9+
"creationDateTime": "2021-03-20",
10+
"updateDateTime": "2023-05-23",
11+
"shortDescription": "This script allows you to add a SharePoint Document Library as a Tab in Microsoft Teams.",
12+
"longDescription": null,
13+
"products": [
14+
"Teams"
15+
],
16+
"categories": [
17+
"Deploy",
18+
"Provision"
19+
],
20+
"tags": [
21+
"Microsoft Teams",
22+
"Governance",
23+
"Connect-PnPOnline",
24+
"Add-PnPTeamsTab",
25+
"m365 login",
26+
"m365 teams team get",
27+
"m365 teams channel get",
28+
"m365 teams tab add",
29+
"m365 logout"
30+
],
31+
"metadata": [
32+
{
33+
"key": "PNP-POWERSHELL",
34+
"value": "3.1.106"
35+
},
36+
{
37+
"key":"CLI-FOR-MICROSOFT365",
38+
"value":"10.10.0"
39+
}
40+
],
41+
"thumbnails": [
42+
{
43+
"type": "image",
44+
"order": 100,
45+
"url": "https://raw.githubusercontent.com/pnp/script-samples/main/scripts/teams-add-sharepointlibrary-as-tab/assets/preview.png",
46+
"alt": "preview image for the sample",
47+
"slides": null
48+
}
49+
],
50+
"authors": [
51+
{
52+
"gitHubAccount": "reshmee011",
53+
"company": "",
54+
"pictureUrl": "https://avatars.githubusercontent.com/u/7693852?v=4",
55+
"name": "Reshmee Auckloo"
56+
}
57+
],
58+
"references": [
59+
{
60+
"name": "Want to learn more about PnP PowerShell and the cmdlets",
61+
"description": "Check out the PnP PowerShell site to get started and for the reference to the cmdlets.",
62+
"url": "https://aka.ms/pnp/powershell"
63+
},
64+
{
65+
"name": "Want to learn more about CLI for Microsoft 365 and the commands",
66+
"description": "Check out the CLI for Microsoft 365 site to get started and for the reference to the commands.",
67+
"url": "https://aka.ms/cli-m365"
68+
}
69+
]
70+
}
71+
]

0 commit comments

Comments
 (0)