From 36fac35513e7b4b45bb6591e1cb105dff1f12ea1 Mon Sep 17 00:00:00 2001 From: Gautam Sheth Date: Mon, 3 Oct 2022 23:31:45 +0300 Subject: [PATCH 1/2] Feature: Retrieve Teams Tag information --- CHANGELOG.md | 1 + documentation/Get-PnPTeamsTag.md | 80 ++++++++++++++++++++++++++ src/Commands/Model/Teams/TeamTag.cs | 16 ++++++ src/Commands/Teams/GetTeamsTag.cs | 41 +++++++++++++ src/Commands/Utilities/TeamsUtility.cs | 17 ++++++ 5 files changed, 155 insertions(+) create mode 100644 documentation/Get-PnPTeamsTag.md create mode 100644 src/Commands/Model/Teams/TeamTag.cs create mode 100644 src/Commands/Teams/GetTeamsTag.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index e3decb29f..83afdae26 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Added `TextBeforeImage` and `TextAfterImage` parameters to `Add-PnPPageTextPart` cmdlet so that users can add before and after text for an inline image into a text webpart. [#2403](https://github.com/pnp/powershell/pull/2403) - Added `Add-PnPPageImageWebPart` cmdlet to allow users to easily add Image to a modern page. - Added Managed Identity support for SharePoint Online cmdlets. [#2354](https://github.com/pnp/powershell/pull/2354) +- Added `Get-PnPTeamsTag` cmdlet to retrieve Team tags information. ### Changed - Changed to no longer require `https://` to be prefixed when using `Connect-PnPOnline -Url tenant.sharepoint.com` [#2139](https://github.com/pnp/powershell/pull/2139) diff --git a/documentation/Get-PnPTeamsTag.md b/documentation/Get-PnPTeamsTag.md new file mode 100644 index 000000000..f3c6f9f6e --- /dev/null +++ b/documentation/Get-PnPTeamsTag.md @@ -0,0 +1,80 @@ +--- +Module Name: PnP.PowerShell +title: Get-PnPTeamsTag +schema: 2.0.0 +applicable: SharePoint Online +external help file: PnP.PowerShell.dll-Help.xml +online version: https://pnp.github.io/powershell/cmdlets/Get-PnPTeamsTag.html +--- + +# Get-PnPTeamsTag + +## SYNOPSIS + +**Required Permissions** + +* Microsoft Graph API : TeamWorkTag.Read, Group.Read.All + +Gets one or all tags in a team. + +## SYNTAX + +```powershell +Get-PnPTeamsTag -Team [-Identity ] +``` + +## DESCRIPTION + +## EXAMPLES + +### EXAMPLE 1 + +```powershell +Get-PnPTeamsTag -Team 5beb63c5-0571-499e-94d5-3279fdd9b6b5 +``` + +Retrieves all the tags for the specified Microsoft Teams instance. + +### EXAMPLE 2 + +```powershell +Get-PnPTeamsTag -Team 5beb63c5-0571-499e-94d5-3279fdd9b6b5 -Identity "ZmY1ZjdmMjctZDhiNy00MWRkLTk2ZDQtYzcyYmVhMWIwOGYxIyM3ZTVhNGRmZS1kNWNlLTRkOTAtODM4MC04ZDIxM2FkYzYzOGIjI3RiVlVpR01rcg==" +``` + +Retrieves a tag with the specified Id from the specified team. + +## PARAMETERS + +### -Identity + +Specify the id of the tag + +```yaml +Type: String +Parameter Sets: (All) + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Team + +Specify the group id, mailNickname or display name of the team to use. + +```yaml +Type: TeamsTeamPipeBind +Parameter Sets: (All) + +Required: True +Position: Named +Default value: None +Accept pipeline input: True (ByValue) +Accept wildcard characters: False +``` + +## RELATED LINKS + +[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp) diff --git a/src/Commands/Model/Teams/TeamTag.cs b/src/Commands/Model/Teams/TeamTag.cs new file mode 100644 index 000000000..3219b6900 --- /dev/null +++ b/src/Commands/Model/Teams/TeamTag.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace PnP.PowerShell.Commands.Model.Teams +{ + public partial class TeamTag + { + public string Id { get; set; } + public string TeamId { get; set; } + public string DisplayName { get; set; } + public string Description { get; set; } + public int MemberCount { get; set; } + public string TagType { get; set; } + } +} diff --git a/src/Commands/Teams/GetTeamsTag.cs b/src/Commands/Teams/GetTeamsTag.cs new file mode 100644 index 000000000..e9dbd38ee --- /dev/null +++ b/src/Commands/Teams/GetTeamsTag.cs @@ -0,0 +1,41 @@ + +using PnP.PowerShell.Commands.Attributes; +using PnP.PowerShell.Commands.Base; +using PnP.PowerShell.Commands.Base.PipeBinds; +using PnP.PowerShell.Commands.Utilities; +using System; +using System.Management.Automation; + +namespace PnP.PowerShell.Commands.Graph +{ + [Cmdlet(VerbsCommon.Get, "PnPTeamsTag")] + [RequiredMinimalApiPermissions("TeamworkTag.Read")] + public class GetTeamsTag : PnPGraphCmdlet + { + [Parameter(Mandatory = true, ValueFromPipeline = true)] + public TeamsTeamPipeBind Team; + + [Parameter(Mandatory = false, ValueFromPipeline = true)] + public string Identity; + + protected override void ExecuteCmdlet() + { + var group = Team.GetGroupId(Connection, AccessToken); + if (string.IsNullOrEmpty(group)) + { + throw new PSArgumentException("Team not found"); + } + + if (!string.IsNullOrEmpty(Identity)) + { + var tags = TeamsUtility.GetTagsWithIdAsync(AccessToken, Connection, group, Identity).GetAwaiter().GetResult(); + WriteObject(tags, false); + } + else + { + var tags = TeamsUtility.GetTagsAsync(AccessToken, Connection, group).GetAwaiter().GetResult(); + WriteObject(tags, true); + } + } + } +} \ No newline at end of file diff --git a/src/Commands/Utilities/TeamsUtility.cs b/src/Commands/Utilities/TeamsUtility.cs index 5fd59874c..cb38af34e 100644 --- a/src/Commands/Utilities/TeamsUtility.cs +++ b/src/Commands/Utilities/TeamsUtility.cs @@ -933,5 +933,22 @@ public static async Task DeleteAppAsync(PnPConnection conne return await GraphHelper.DeleteAsync(connection, $"v1.0/appCatalogs/teamsApps/{appId}", accessToken); } #endregion + + #region Tags + + public static async Task> GetTagsAsync(string accessToken, PnPConnection connection, string groupId) + { + var collection = await GraphHelper.GetResultCollectionAsync(connection, $"beta/teams/{groupId}/tags", accessToken); + return collection; + } + + public static async Task GetTagsWithIdAsync(string accessToken, PnPConnection connection, string groupId, string tagId) + { + var tagInformation = await GraphHelper.GetAsync(connection, $"beta/teams/{groupId}/tags/{tagId}", accessToken); + return tagInformation; + } + + + #endregion } } \ No newline at end of file From e4fa805fcfb8e6b6875b2e16fc024517ea9dda1f Mon Sep 17 00:00:00 2001 From: Koen Zomers Date: Tue, 4 Oct 2022 16:56:40 +0200 Subject: [PATCH 2/2] Update CHANGELOG.md Added PR reference --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 83afdae26..a7355f007 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,7 +29,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Added `TextBeforeImage` and `TextAfterImage` parameters to `Add-PnPPageTextPart` cmdlet so that users can add before and after text for an inline image into a text webpart. [#2403](https://github.com/pnp/powershell/pull/2403) - Added `Add-PnPPageImageWebPart` cmdlet to allow users to easily add Image to a modern page. - Added Managed Identity support for SharePoint Online cmdlets. [#2354](https://github.com/pnp/powershell/pull/2354) -- Added `Get-PnPTeamsTag` cmdlet to retrieve Team tags information. +- Added `Get-PnPTeamsTag` cmdlet to retrieve Team tags information. [#2414](https://github.com/pnp/powershell/pull/2414) ### Changed - Changed to no longer require `https://` to be prefixed when using `Connect-PnPOnline -Url tenant.sharepoint.com` [#2139](https://github.com/pnp/powershell/pull/2139)