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

Implements advanced queries to Get-PnPTeamsTeam #2474

Merged
merged 2 commits into from
Oct 16, 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
9 changes: 8 additions & 1 deletion documentation/Get-PnPTeamsTeam.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Get-PnPTeamsTeam [-Identity <TeamsTeamPipeBind>] [-Filter <String>] [<CommonPar

## DESCRIPTION

Allows to retrieve list of Microsoft Teams teams. By using `Identity` it is possible to retrieve a specific team, and by using `Filter` you can supply simple filter queries.
Allows to retrieve list of Microsoft Teams teams. By using `Identity` it is possible to retrieve a specific team, and by using `Filter` you can supply any filter queries supported by the Graph API.

## EXAMPLES

Expand Down Expand Up @@ -57,6 +57,13 @@ Get-PnPTeamsTeam -Filter "startswith(mailNickName, 'contoso')"

Retrieves all Microsoft Teams instances with MailNickName starting with "contoso".

### EXAMPLE 5
```powershell
Get-PnPTeamsTeam -Filter "startswith(description, 'contoso')"
```

Retrieves all Microsoft Teams instances with Description starting with "contoso". This example demonstrates using Advanced Query capabilities (see: https://learn.microsoft.com/en-us/graph/aad-advanced-queries?tabs=http#group-properties).

## PARAMETERS

### -Identity
Expand Down
17 changes: 16 additions & 1 deletion src/Commands/Utilities/TeamsUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,30 @@ internal static class TeamsUtility
#region Team
public static async Task<List<Group>> GetGroupsWithTeamAsync(PnPConnection connection, string accessToken, string filter = null)
{
Dictionary<string, string> additionalHeaders = null;
string requestUrl;

if (String.IsNullOrEmpty(filter))
{
filter = "resourceProvisioningOptions/Any(x:x eq 'Team')";

requestUrl = $"v1.0/groups?$filter={filter}&$select=Id,DisplayName,MailNickName,Description,Visibility&$top={PageSize}";

}
else
{
filter = $"({filter}) and resourceProvisioningOptions/Any(x:x eq 'Team')";

// This query requires ConsistencyLevel header to be set, since "Filter" could have some advanced queries supplied by the user.
additionalHeaders = new Dictionary<string, string>();
additionalHeaders.Add("ConsistencyLevel", "eventual");

// $count=true needs to be here for reasons
// see this for some additional details: https://learn.microsoft.com/en-us/graph/aad-advanced-queries?tabs=http#group-properties
requestUrl = $"v1.0/groups?$filter={filter}&$select=Id,DisplayName,MailNickName,Description,Visibility&$top={PageSize}&$count=true";
}
var collection = await GraphHelper.GetResultCollectionAsync<Group>(connection, $"v1.0/groups?$filter={filter}&$select=Id,DisplayName,MailNickName,Description,Visibility&$top={PageSize}", accessToken);

var collection = await GraphHelper.GetResultCollectionAsync<Group>(connection, requestUrl, accessToken, additionalHeaders: additionalHeaders);
return collection.ToList();
}

Expand Down