-
Notifications
You must be signed in to change notification settings - Fork 359
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2419 from gautamdsheth/feature/teamwork-tag-list
Feature: Add Set/Remove-PnPTeamsTag cmdlets
- Loading branch information
Showing
9 changed files
with
332 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
--- | ||
Module Name: PnP.PowerShell | ||
title: Remove-PnPTeamsTag | ||
schema: 2.0.0 | ||
applicable: SharePoint Online | ||
external help file: PnP.PowerShell.dll-Help.xml | ||
online version: https://pnp.github.io/powershell/cmdlets/Remove-PnPTeamsTag.html | ||
--- | ||
|
||
# Remove-PnPTeamsTag | ||
|
||
## SYNOPSIS | ||
|
||
**Required Permissions** | ||
|
||
* Microsoft Graph API: TeamworkTag.ReadWrite, Group.Read.All | ||
|
||
Removes a Microsoft Teams Tag in a Team. | ||
|
||
## SYNTAX | ||
|
||
```powershell | ||
Remove-PnPTeamsTag -Team <TeamsTeamPipeBind> -Identity <TeamsTagPipeBind> [-Force] | ||
``` | ||
|
||
## DESCRIPTION | ||
|
||
## EXAMPLES | ||
|
||
### EXAMPLE 1 | ||
```powershell | ||
Remove-PnPTeamsTag -Team 5beb63c5-0571-499e-94d5-3279fdd9b6b5 -Identity "ZmY1ZjdmMjctZDhiNy00MWRkLTk2ZDQtYzcyYmVhMWIwOGYxIyM3ZTVhNGRmZS1kNWNlLTRkOTAtODM4MC04ZDIxM2FkYzYzOGIjI3RiVlVpR01rcg==" | ||
``` | ||
Removes the Tag with the specified Id from the Teams team. | ||
|
||
## PARAMETERS | ||
|
||
### -Force | ||
Specifying the Force parameter will skip the confirmation question. | ||
|
||
```yaml | ||
Type: SwitchParameter | ||
Parameter Sets: (All) | ||
|
||
Required: False | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
### -Identity | ||
Specify the id of the Tag | ||
```yaml | ||
Type: TeamsTagPipeBind | ||
Parameter Sets: (All) | ||
|
||
Required: True | ||
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: False | ||
Accept wildcard characters: False | ||
``` | ||
## RELATED LINKS | ||
[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp) | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
--- | ||
Module Name: PnP.PowerShell | ||
title: Set-PnPTeamsTag | ||
schema: 2.0.0 | ||
applicable: SharePoint Online | ||
external help file: PnP.PowerShell.dll-Help.xml | ||
online version: https://pnp.github.io/powershell/cmdlets/Set-PnPTeamsTag.html | ||
--- | ||
|
||
# Set-PnPTeamsTag | ||
|
||
## SYNOPSIS | ||
|
||
**Required Permissions** | ||
|
||
* Microsoft Graph API: TeamworkTag.ReadWrite, Group.Read.All | ||
|
||
Sets the Microsoft Teams Tag in a Team. | ||
|
||
## SYNTAX | ||
|
||
```powershell | ||
Set-PnPTeamsTag -Team <TeamsTeamPipeBind> -Identity <TeamsTagPipeBind> -DisplayName <String> | ||
``` | ||
|
||
## DESCRIPTION | ||
|
||
## EXAMPLES | ||
|
||
### EXAMPLE 1 | ||
```powershell | ||
Set-PnPTeamsTag -Team 5beb63c5-0571-499e-94d5-3279fdd9b6b5 -Identity "ZmY1ZjdmMjctZDhiNy00MWRkLTk2ZDQtYzcyYmVhMWIwOGYxIyM3ZTVhNGRmZS1kNWNlLTRkOTAtODM4MC04ZDIxM2FkYzYzOGIjI3RiVlVpR01rcg==" -DisplayName "Updated Tag" | ||
``` | ||
Sets the Tag with the specified Id from the Teams team. | ||
|
||
## PARAMETERS | ||
|
||
### -DisplayName | ||
The updated display name of the Teams tag | ||
|
||
```yaml | ||
Type: String | ||
Parameter Sets: (All) | ||
|
||
Required: False | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
### -Identity | ||
Specify the id of the Tag | ||
```yaml | ||
Type: TeamsTagPipeBind | ||
Parameter Sets: (All) | ||
|
||
Required: True | ||
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: False | ||
Accept wildcard characters: False | ||
``` | ||
## RELATED LINKS | ||
[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp) | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using PnP.PowerShell.Commands.Model.Teams; | ||
using PnP.PowerShell.Commands.Utilities; | ||
using System; | ||
using System.Linq; | ||
using System.Net.Http; | ||
|
||
namespace PnP.PowerShell.Commands.Base.PipeBinds | ||
{ | ||
public sealed class TeamsTagPipeBind | ||
{ | ||
private readonly string _id; | ||
public TeamsTagPipeBind() | ||
{ | ||
} | ||
|
||
public TeamsTagPipeBind(string input) | ||
{ | ||
_id = input; | ||
} | ||
|
||
public TeamsTagPipeBind(TeamTag tag) | ||
{ | ||
_id = tag.Id; | ||
} | ||
|
||
|
||
public TeamTag GetTag(PnPConnection connection, string accessToken, string groupId) | ||
{ | ||
var tags = TeamsUtility.GetTagsAsync(accessToken, connection, groupId).GetAwaiter().GetResult(); | ||
if (tags != null && tags.Any()) | ||
{ | ||
return tags.FirstOrDefault(c => c.Id.Equals(_id, StringComparison.OrdinalIgnoreCase)); | ||
} | ||
return null; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
using PnP.PowerShell.Commands.Attributes; | ||
using PnP.PowerShell.Commands.Base; | ||
using PnP.PowerShell.Commands.Base.PipeBinds; | ||
using PnP.PowerShell.Commands.Model.Graph; | ||
using PnP.PowerShell.Commands.Utilities; | ||
using PnP.PowerShell.Commands.Utilities.REST; | ||
using System.Management.Automation; | ||
|
||
namespace PnP.PowerShell.Commands.Graph | ||
{ | ||
[Cmdlet(VerbsCommon.Remove, "PnPTeamsTag")] | ||
[RequiredMinimalApiPermissions("TeamworkTag.ReadWrite")] | ||
public class RemoveTeamsTag : PnPGraphCmdlet | ||
{ | ||
[Parameter(Mandatory = true)] | ||
public TeamsTeamPipeBind Team; | ||
|
||
[Parameter(Mandatory = true)] | ||
public TeamsTagPipeBind Identity; | ||
|
||
[Parameter(Mandatory = false)] | ||
public SwitchParameter Force; | ||
|
||
protected override void ExecuteCmdlet() | ||
{ | ||
var groupId = Team.GetGroupId(Connection, AccessToken); | ||
if (groupId != null) | ||
{ | ||
var tag = Identity.GetTag(Connection, AccessToken, groupId); | ||
if (tag != null) | ||
{ | ||
if (Force || ShouldContinue("Do you want to remove this tag ?", Properties.Resources.Confirm)) | ||
{ | ||
var response = TeamsUtility.DeleteTagAsync(Connection, AccessToken, groupId, tag.Id).GetAwaiter().GetResult(); | ||
if (!response.IsSuccessStatusCode) | ||
{ | ||
if (GraphHelper.TryGetGraphException(response, out GraphException ex)) | ||
{ | ||
if (ex.Error != null) | ||
{ | ||
throw new PSInvalidOperationException(ex.Error.Message); | ||
} | ||
} | ||
else | ||
{ | ||
throw new PSInvalidOperationException("Tag remove failed"); | ||
} | ||
} | ||
} | ||
} | ||
else | ||
{ | ||
throw new PSArgumentException("Tag not found"); | ||
} | ||
} | ||
else | ||
{ | ||
throw new PSArgumentException("Team not found", nameof(Team)); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
using PnP.PowerShell.Commands.Attributes; | ||
using PnP.PowerShell.Commands.Base; | ||
using PnP.PowerShell.Commands.Base.PipeBinds; | ||
using PnP.PowerShell.Commands.Utilities; | ||
using System.Management.Automation; | ||
|
||
namespace PnP.PowerShell.Commands.Graph | ||
{ | ||
[Cmdlet(VerbsCommon.Set, "PnPTeamsTag")] | ||
[RequiredMinimalApiPermissions("TeamworkTag.ReadWrite")] | ||
public class SetTeamsTag : PnPGraphCmdlet | ||
{ | ||
[Parameter(Mandatory = true, ValueFromPipeline = true)] | ||
public TeamsTeamPipeBind Team; | ||
|
||
[Parameter(Mandatory = true, ValueFromPipeline = true)] | ||
public TeamsTagPipeBind Identity; | ||
|
||
[Parameter(Mandatory = true)] | ||
public string DisplayName; | ||
|
||
protected override void ExecuteCmdlet() | ||
{ | ||
var groupId = Team.GetGroupId(Connection, AccessToken); | ||
if (groupId != null) | ||
{ | ||
var tag = Identity.GetTag(Connection, AccessToken, groupId); | ||
if (tag != null) | ||
{ | ||
if (ParameterSpecified(nameof(DisplayName)) && tag.DisplayName != DisplayName) | ||
{ | ||
TeamsUtility.UpdateTagAsync(Connection, AccessToken, groupId, tag.Id, DisplayName).GetAwaiter().GetResult(); | ||
} | ||
} | ||
else | ||
{ | ||
throw new PSArgumentException("Tag not found"); | ||
} | ||
} | ||
else | ||
{ | ||
throw new PSArgumentException("Team not found"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters