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 #995 - ability to fetch guest users from the team #1474

Merged
merged 8 commits into from
Jan 27, 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 @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).

### Added

- Added additional properties to the users returned by `Get-PnPMicrosoft365GroupMember` such as `userType` [#1474](https://github.com/pnp/powershell/pull/1474)
- Added `Update-PnPTeamsUser` cmdlet to change the role of a user in an existing Teams team [#1499](https://github.com/pnp/powershell/pull/1499)
- Added `Get\New\Remove\Set-PnPMicrosoft365GroupSettings` cmdlets to interact with Microsoft 365 Group settings.
- Added `Get-PnPMicrosoft365GroupSettingTemplates` cmdlet to retrieve system wide Microsoft 365 Group setting templates.
Expand Down
16 changes: 11 additions & 5 deletions documentation/Get-PnPMicrosoft365GroupMember.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@ title: Get-PnPMicrosoft365GroupMember
* Microsoft Graph API : at least Group.Read.All
* Microsoft Graph API : Directory.Read.All

Gets members of a particular Microsoft 365 Group (aka Unified Group).
Returns the members of a particular Microsoft 365 Group

## SYNTAX

```powershell
Get-PnPMicrosoft365GroupMember -Identity <Microsoft365GroupPipeBind> [<CommonParameters>]
Get-PnPMicrosoft365GroupMember -Identity <Microsoft365GroupPipeBind> [-UserType <String>] [<CommonParameters>]
```

## DESCRIPTION
Returns the members of a particular Microsoft 365 Group

## EXAMPLES

Expand All @@ -42,6 +43,13 @@ Get-PnPMicrosoft365GroupMember -Identity $group

Retrieves all the members of a specific Microsoft 365 Group based on the group's object instance

### EXAMPLE 3
```powershell
Get-PnPMicrosoft365GroupMember -Identity "Sales" | Where-Object UserType -eq Guest
```

Returns all the guest users of the Microsoft 365 Group named "Sales"

## PARAMETERS

### -Identity
Expand All @@ -60,6 +68,4 @@ Accept wildcard characters: False
## RELATED LINKS
[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)
[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)
18 changes: 18 additions & 0 deletions src/Commands/Enums/UserType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace PnP.PowerShell.Commands.Enums
{
/// <summary>
/// Enum that defines the possible types of users
/// </summary>
public enum UserType
{
/// <summary>
/// User is an employee account
/// </summary>
Member = 0,

/// <summary>
/// User is a guest account
/// </summary>
Guest = 1
}
}
3 changes: 0 additions & 3 deletions src/Commands/Model/Microsoft365Group.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
using System.Text.Json;
using System.Text.Json.Serialization;
using PnP.PowerShell.Commands.Model.Graph;

namespace PnP.PowerShell.Commands.Model
{
Expand Down
60 changes: 51 additions & 9 deletions src/Commands/Model/Microsoft365User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,88 @@

namespace PnP.PowerShell.Commands.Model
{
/// <summary>
/// Contains the information of an Azure Active Directory user object
/// </summary>
public class Microsoft365User
{
/// <summary>
/// Unique identifier of this user object in Azure Active Directory
/// </summary>
[JsonPropertyName("id")]
public string Id { get; set; }

/// <summary>
/// Group user's user principal name
/// User's user principal name
/// </summary>
[JsonPropertyName("userPrincipalName")]
public string UserPrincipalName { get; set; }

/// <summary>
/// Group user's display name
/// User's display name
/// </summary>
[JsonPropertyName("displayName")]
public string DisplayName { get; set; }

/// <summary>
/// Group user's given name
/// User's given name
/// </summary>
[JsonPropertyName("givenName")]
public string GivenName { get; set; }

/// <summary>
/// Group user's surname
/// User's surname
/// </summary>
[JsonPropertyName("surname")]
public string Surname { get; set; }

/// <summary>
/// Group user's e-mail address
/// User's e-mail address
/// </summary>

[JsonPropertyName("mail")]
public string Email { get; set; }

/// <summary>
/// Group user's mobile phone number
/// User's mobile phone number
/// </summary>
[JsonPropertyName("mobilePhone")]
public string MobilePhone { get; set; }

/// <summary>
/// Group user's preferred language in ISO 639-1 standard notation
/// User's preferred language in ISO 639-1 standard notation
/// </summary>
[JsonPropertyName("preferredLanguage")]
public string PreferredLanguage { get; set; }

/// <summary>
/// Group user's job title
/// User's job title
/// </summary>
[JsonPropertyName("jobTitle")]
public string JobTitle { get; set; }

/// <summary>
/// Group user's business phone numbers
/// User's business phone numbers
/// </summary>
[JsonPropertyName("businessPhones")]
public string[] BusinessPhones { get; set; }

/// <summary>
/// User's job title
/// </summary>
[JsonPropertyName("userType")]
public Enums.UserType? UserType { get; set; }

/// <summary>
/// Location from which Microsoft 365 will mainly be used
/// </summary>
[JsonPropertyName("usageLocation")]
public string UsageLocation { get; set; }

/// <summary>
/// Aliases set on the mailbox of this user
/// </summary>
[JsonPropertyName("proxyAddresses")]
public string[] ProxyAddresses { get; set; }
}
}
4 changes: 2 additions & 2 deletions src/Commands/Utilities/Microsoft365GroupsUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ internal static async Task<IEnumerable<Microsoft365User>> GetMembersAsync(HttpCl
return await GetGroupMembersAsync("members", httpClient, groupId, accessToken);
}

private static async Task<IEnumerable<Microsoft365User>> GetGroupMembersAsync(string groupName, HttpClient httpClient, Guid groupId, string accessToken)
private static async Task<IEnumerable<Microsoft365User>> GetGroupMembersAsync(string userType, HttpClient httpClient, Guid groupId, string accessToken)
{
var results = await GraphHelper.GetResultCollectionAsync<Microsoft365User>(httpClient, $"v1.0/groups/{groupId}/{groupName}", accessToken);
var results = await GraphHelper.GetResultCollectionAsync<Microsoft365User>(httpClient, $"v1.0/groups/{groupId}/{userType}?$select=*", accessToken);
return results;
}

Expand Down
6 changes: 4 additions & 2 deletions src/Commands/Utilities/REST/GraphHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Net;
using System.Net.Http;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading;
using System.Threading.Tasks;

Expand Down Expand Up @@ -124,7 +125,8 @@ public static async Task<T> GetAsync<T>(HttpClient httpClient, string url, strin
var stringContent = await GetAsync(httpClient, url, accessToken);
if (stringContent != null)
{
var options = new JsonSerializerOptions() { IgnoreNullValues = true };
var options = new JsonSerializerOptions { IgnoreNullValues = true };
options.Converters.Add(new JsonStringEnumConverter());
if (camlCasePolicy)
{
options.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
Expand All @@ -138,7 +140,7 @@ public static async Task<T> GetAsync<T>(HttpClient httpClient, string url, strin
var entity = JsonSerializer.Deserialize<T>(stringContent, options);
return entity;
}
catch (Exception)
catch (Exception e)
{
return default(T);
}
Expand Down