Skip to content

Commit

Permalink
Merge pull request #1572 from reshmee011/dev
Browse files Browse the repository at this point in the history
New cmdlet Get-PnPTeamsPrimaryChannel to get primary channel
  • Loading branch information
KoenZomers authored Jan 27, 2022
2 parents 34f4498 + d1083b0 commit 7759f26
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 5 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Added `Add\Remove\Set-PnPAdaptiveScopeProperty` cmdlets to add/update/remove a property bag value while dealing with the noscript toggling in one cmdlet [#1556](https://github.com/pnp/powershell/pull/1556)
- Added support to add multiple owners and members in `New-PnPTeamsTeam` cmdlet [#1241](https://github.com/pnp/powershell/pull/1241)
- Added the ability to set the title of a new modern page in SharePoint Online using `Add-PnPPage` to be different from its filename by using `-Title`

- Added `Get-PnPTeamsPrimaryChannel` to get the primary Teams channel, general, of a Team [#1572](https://github.com/pnp/powershell/pull/1572)

### Changed

- Improved `Add-PnPTeamsUser` cmdlet. The cmdlet executes faster and we can now add users in batches of 200. [#1548](https://github.com/pnp/powershell/pull/1548)
Expand Down Expand Up @@ -57,6 +58,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Brendon Lee [brenle]
- Guillaume Bordier [gbordier]
- [reusto]
- Reshmee Auckloo [reshmee011]
- Gautam Sheth [gautamdsheth]
- Koen Zomers [koenzomers]

Expand Down
65 changes: 65 additions & 0 deletions documentation/Get-PnPTeamsPrimaryChannel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
Module Name: PnP.PowerShell
title: Get-PnPTeamsPrimaryChannel
schema: 2.0.0
applicable: SharePoint Online
external help file: PnP.PowerShell.dll-Help.xml
online version: https://pnp.github.io/powershell/cmdlets/Get-PnPTeamsPrimaryChannel.html
---

# Get-PnPTeamsPrimaryChannel

## SYNOPSIS

**Required Permissions**

* Microsoft Graph API : Channel.ReadBasic.All, ChannelSettings.Read.All, ChannelSettings.ReadWrite.All

Gets the default channel, General, of a team.

## SYNTAX

```powershell
Get-PnPTeamsPrimaryChannel -Team <TeamsTeamPipeBind> [-Identity <TeamsChannelPipeBind>]
[<CommonParameters>]
```

## DESCRIPTION
Gets the default channel, General, of a team.

## EXAMPLES

### EXAMPLE 1
```powershell
Get-PnPTeamsPrimaryChannel -Team ee0f40fc-b2f7-45c7-b62d-11b90dd2ea8e
```

Gets the default channel of the Team with the provided Id

### EXAMPLE 2
```powershell
Get-PnPTeamsPrimaryChannel -Team Sales
```

Gets the default channel of the Sales Team

## PARAMETERS

### -Team
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)
[Microsoft Graph documentation](https://docs.microsoft.com/graph/api/team-get-primarychannel)
17 changes: 14 additions & 3 deletions src/Commands/Model/Teams/TeamChannel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace PnP.PowerShell.Commands.Model.Teams
Expand Down Expand Up @@ -37,12 +38,22 @@ public partial class TeamChannel
/// Defines the Description of the Channel
/// </summary>
public string Description { get; set; }

/// <summary>
/// Created date time for the channel
/// </summary>
public DateTime? CreatedDateTime { get; set; }
/// <summary>
/// Email for the channel
/// </summary>
public string Email { get; set; }
/// <summary>
/// web url of the channel
/// </summary>
public string WebUrl { get; set; }
/// <summary>
/// Defines whether the Channel is Favorite by default for all members of the Team
/// </summary>
public bool? IsFavoriteByDefault { get; set; }

/// <summary>
/// Declares the ID for the Channel
/// </summary>
Expand Down
33 changes: 33 additions & 0 deletions src/Commands/Teams/GetTeamsPrimaryChannel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using PnP.Framework.Graph;
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.Collections.Generic;
using System.Linq;
using System.Management.Automation;

namespace PnP.PowerShell.Commands.Teams
{
[Cmdlet(VerbsCommon.Get, "PnPTeamsPrimaryChannel")]
[RequiredMinimalApiPermissions("Channel.ReadBasic.All")]

public class GetTeamsPrimaryChannel : PnPGraphCmdlet
{
[Parameter(Mandatory = true, ValueFromPipeline = true)]
public TeamsTeamPipeBind Team;

protected override void ExecuteCmdlet()
{
var groupId = Team.GetGroupId(HttpClient, AccessToken);
if (groupId != null)
{
WriteObject(TeamsUtility.GetPrimaryChannelAsync(AccessToken, HttpClient, groupId).GetAwaiter().GetResult());
} else
{
throw new PSArgumentException("Team not found", nameof(Team));
}
}
}
}
6 changes: 5 additions & 1 deletion src/Commands/Utilities/TeamsUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,11 @@ public static async Task<IEnumerable<TeamChannel>> GetChannelsAsync(string acces
var collection = await GraphHelper.GetResultCollectionAsync<TeamChannel>(httpClient, $"v1.0/teams/{groupId}/channels", accessToken);
return collection;
}

public static async Task<TeamChannel> GetPrimaryChannelAsync(string accessToken, HttpClient httpClient, string groupId)
{
var collection = await GraphHelper.GetAsync<TeamChannel>(httpClient, $"v1.0/teams/{groupId}/primaryChannel", accessToken);
return collection;
}
public static async Task<HttpResponseMessage> DeleteChannelAsync(string accessToken, HttpClient httpClient, string groupId, string channelId)
{
return await GraphHelper.DeleteAsync(httpClient, $"v1.0/teams/{groupId}/channels/{channelId}", accessToken);
Expand Down

0 comments on commit 7759f26

Please sign in to comment.