-
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 #1735 from milanholemans/add-channel-user-command
Created Add-PnpTeamsChannelUser cmdlet
- Loading branch information
Showing
5 changed files
with
178 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
--- | ||
Module Name: PnP.PowerShell | ||
schema: 2.0.0 | ||
applicable: SharePoint Online | ||
online version: https://pnp.github.io/powershell/cmdlets/Add-PnPTeamsChannelUser.html | ||
external help file: PnP.PowerShell.dll-Help.xml | ||
title: Add-PnPTeamsChannelUser | ||
--- | ||
|
||
# Add-PnPTeamsChannelUser | ||
|
||
## SYNOPSIS | ||
|
||
**Required Permissions** | ||
|
||
* Microsoft Graph API: ChannelMember.ReadWrite.All | ||
|
||
Adds a user to an existing Microsoft Teams private channel. | ||
|
||
## SYNTAX | ||
|
||
```powershell | ||
Add-PnPTeamsChannelUser -Team <TeamsTeamPipeBind> -Channel <TeamsChannelPipeBind> -User <String> -Role <String> [<CommonParameters>] | ||
``` | ||
|
||
## DESCRIPTION | ||
|
||
## EXAMPLES | ||
|
||
### EXAMPLE 1 | ||
```powershell | ||
Add-PnPTeamsChannelUser -Team 4efdf392-8225-4763-9e7f-4edeb7f721aa -Channel "19:[email protected]" -User [email protected] -Role Owner | ||
``` | ||
|
||
Adds user as an owner to the private channel. | ||
|
||
### EXAMPLE 2 | ||
```powershell | ||
Add-PnPTeamsChannelUser -Team "My Team" -Channel "My Private Channel" -User [email protected] -Role Member | ||
``` | ||
|
||
Adds user as a member to the private channel. | ||
|
||
## PARAMETERS | ||
|
||
### -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 | ||
``` | ||
### -Channel | ||
The id or name of the channel to retrieve. | ||
```yaml | ||
Type: TeamsChannelPipeBind | ||
Parameter Sets: (All) | ||
|
||
Required: False | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
### -User | ||
Specify the UPN (e.g. [email protected]) | ||
```yaml | ||
Type: String | ||
Parameter Sets: (User) | ||
|
||
Required: True | ||
Position: Named | ||
Default value: None | ||
Accept pipeline input: False | ||
Accept wildcard characters: False | ||
``` | ||
### -Role | ||
Specify the role of the user | ||
```yaml | ||
Type: String | ||
Parameter Sets: (All) | ||
Accepted values: Owner, Member | ||
|
||
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 |
---|---|---|
|
@@ -26,6 +26,4 @@ public class TeamChannelMember | |
[JsonPropertyName("email")] | ||
public string email { get; set; } | ||
} | ||
|
||
|
||
} |
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,56 @@ | ||
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 System.Management.Automation; | ||
|
||
namespace PnP.PowerShell.Commands.Teams | ||
{ | ||
[Cmdlet(VerbsCommon.Add, "PnPTeamsChannelUser")] | ||
[RequiredMinimalApiPermissions("ChannelMember.ReadWrite.All")] | ||
public class AddTeamsChannelUser : PnPGraphCmdlet | ||
{ | ||
[Parameter(Mandatory = true)] | ||
public TeamsTeamPipeBind Team; | ||
|
||
[Parameter(Mandatory = true)] | ||
public TeamsChannelPipeBind Channel; | ||
|
||
[Parameter(Mandatory = true)] | ||
public string User; | ||
|
||
[Parameter(Mandatory = true)] | ||
[ValidateSet("Owner", "Member")] | ||
public string Role; | ||
|
||
protected override void ExecuteCmdlet() | ||
{ | ||
var groupId = Team.GetGroupId(HttpClient, AccessToken); | ||
if (groupId == null) | ||
{ | ||
throw new PSArgumentException("Group not found"); | ||
} | ||
|
||
var channelId = Channel.GetId(HttpClient, AccessToken, groupId); | ||
if (channelId == null) | ||
{ | ||
throw new PSArgumentException("Channel not found"); | ||
} | ||
|
||
try | ||
{ | ||
TeamsUtility.AddChannelUserAsync(HttpClient, AccessToken, groupId, channelId, User, Role).GetAwaiter().GetResult(); | ||
} | ||
catch (GraphException ex) | ||
{ | ||
if (ex.Error != null) | ||
{ | ||
throw new PSInvalidOperationException(ex.Error.Message); | ||
} | ||
|
||
throw; | ||
} | ||
} | ||
} | ||
} |
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