diff --git a/scripts/teams-add-sharepointlibrary-as-tab/README.md b/scripts/teams-add-sharepointlibrary-as-tab/README.md new file mode 100644 index 00000000..a3c9aa05 --- /dev/null +++ b/scripts/teams-add-sharepointlibrary-as-tab/README.md @@ -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)] + diff --git a/scripts/teams-add-sharepointlibrary-as-tab/assets/example.png b/scripts/teams-add-sharepointlibrary-as-tab/assets/example.png new file mode 100644 index 00000000..9feb18d9 Binary files /dev/null and b/scripts/teams-add-sharepointlibrary-as-tab/assets/example.png differ diff --git a/scripts/teams-add-sharepointlibrary-as-tab/assets/preview.png b/scripts/teams-add-sharepointlibrary-as-tab/assets/preview.png new file mode 100644 index 00000000..b6e7a04e Binary files /dev/null and b/scripts/teams-add-sharepointlibrary-as-tab/assets/preview.png differ diff --git a/scripts/teams-add-sharepointlibrary-as-tab/assets/sample.json b/scripts/teams-add-sharepointlibrary-as-tab/assets/sample.json new file mode 100644 index 00000000..282fb95d --- /dev/null +++ b/scripts/teams-add-sharepointlibrary-as-tab/assets/sample.json @@ -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" + } + ] + } +]