Skip to content
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

Feature: Retrieve Teams Tag information #2414

Merged
merged 2 commits into from
Oct 4, 2022
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. [#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)
Expand Down
80 changes: 80 additions & 0 deletions documentation/Get-PnPTeamsTag.md
Original file line number Diff line number Diff line change
@@ -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 <TeamsTeamPipeBind> [-Identity <string>]
```

## 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)
16 changes: 16 additions & 0 deletions src/Commands/Model/Teams/TeamTag.cs
Original file line number Diff line number Diff line change
@@ -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; }
}
}
41 changes: 41 additions & 0 deletions src/Commands/Teams/GetTeamsTag.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
}
17 changes: 17 additions & 0 deletions src/Commands/Utilities/TeamsUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -933,5 +933,22 @@ public static async Task<HttpResponseMessage> DeleteAppAsync(PnPConnection conne
return await GraphHelper.DeleteAsync(connection, $"v1.0/appCatalogs/teamsApps/{appId}", accessToken);
}
#endregion

#region Tags

public static async Task<IEnumerable<TeamTag>> GetTagsAsync(string accessToken, PnPConnection connection, string groupId)
{
var collection = await GraphHelper.GetResultCollectionAsync<TeamTag>(connection, $"beta/teams/{groupId}/tags", accessToken);
return collection;
}

public static async Task<TeamTag> GetTagsWithIdAsync(string accessToken, PnPConnection connection, string groupId, string tagId)
{
var tagInformation = await GraphHelper.GetAsync<TeamTag>(connection, $"beta/teams/{groupId}/tags/{tagId}", accessToken);
return tagInformation;
}


#endregion
}
}