diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a84d3bab..f72c0ac5a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/documentation/Get-PnPMicrosoft365GroupMember.md b/documentation/Get-PnPMicrosoft365GroupMember.md index 78e2a9d74..98e51f016 100644 --- a/documentation/Get-PnPMicrosoft365GroupMember.md +++ b/documentation/Get-PnPMicrosoft365GroupMember.md @@ -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 [] +Get-PnPMicrosoft365GroupMember -Identity [-UserType ] [] ``` ## DESCRIPTION +Returns the members of a particular Microsoft 365 Group ## EXAMPLES @@ -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 @@ -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) \ No newline at end of file diff --git a/src/Commands/Enums/UserType.cs b/src/Commands/Enums/UserType.cs new file mode 100644 index 000000000..f470370da --- /dev/null +++ b/src/Commands/Enums/UserType.cs @@ -0,0 +1,18 @@ +namespace PnP.PowerShell.Commands.Enums +{ + /// + /// Enum that defines the possible types of users + /// + public enum UserType + { + /// + /// User is an employee account + /// + Member = 0, + + /// + /// User is a guest account + /// + Guest = 1 + } +} diff --git a/src/Commands/Model/Microsoft365Group.cs b/src/Commands/Model/Microsoft365Group.cs index af1309e09..744a5ecba 100644 --- a/src/Commands/Model/Microsoft365Group.cs +++ b/src/Commands/Model/Microsoft365Group.cs @@ -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 { diff --git a/src/Commands/Model/Microsoft365User.cs b/src/Commands/Model/Microsoft365User.cs index 97f7bcc0b..09b2feaf3 100644 --- a/src/Commands/Model/Microsoft365User.cs +++ b/src/Commands/Model/Microsoft365User.cs @@ -2,46 +2,88 @@ namespace PnP.PowerShell.Commands.Model { + /// + /// Contains the information of an Azure Active Directory user object + /// public class Microsoft365User { + /// + /// Unique identifier of this user object in Azure Active Directory + /// + [JsonPropertyName("id")] public string Id { get; set; } + /// - /// Group user's user principal name + /// User's user principal name /// + [JsonPropertyName("userPrincipalName")] public string UserPrincipalName { get; set; } + /// - /// Group user's display name + /// User's display name /// + [JsonPropertyName("displayName")] public string DisplayName { get; set; } + /// - /// Group user's given name + /// User's given name /// + [JsonPropertyName("givenName")] public string GivenName { get; set; } + /// - /// Group user's surname + /// User's surname /// + [JsonPropertyName("surname")] public string Surname { get; set; } + /// - /// Group user's e-mail address + /// User's e-mail address /// [JsonPropertyName("mail")] public string Email { get; set; } + /// - /// Group user's mobile phone number + /// User's mobile phone number /// + [JsonPropertyName("mobilePhone")] public string MobilePhone { get; set; } + /// - /// Group user's preferred language in ISO 639-1 standard notation + /// User's preferred language in ISO 639-1 standard notation /// + [JsonPropertyName("preferredLanguage")] public string PreferredLanguage { get; set; } + /// - /// Group user's job title + /// User's job title /// + [JsonPropertyName("jobTitle")] public string JobTitle { get; set; } + /// - /// Group user's business phone numbers + /// User's business phone numbers /// + [JsonPropertyName("businessPhones")] public string[] BusinessPhones { get; set; } + + /// + /// User's job title + /// + [JsonPropertyName("userType")] + public Enums.UserType? UserType { get; set; } + + /// + /// Location from which Microsoft 365 will mainly be used + /// + [JsonPropertyName("usageLocation")] + public string UsageLocation { get; set; } + + /// + /// Aliases set on the mailbox of this user + /// + [JsonPropertyName("proxyAddresses")] + public string[] ProxyAddresses { get; set; } } } \ No newline at end of file diff --git a/src/Commands/Utilities/Microsoft365GroupsUtility.cs b/src/Commands/Utilities/Microsoft365GroupsUtility.cs index 9e29ab564..9c02fb63e 100644 --- a/src/Commands/Utilities/Microsoft365GroupsUtility.cs +++ b/src/Commands/Utilities/Microsoft365GroupsUtility.cs @@ -230,9 +230,9 @@ internal static async Task> GetMembersAsync(HttpCl return await GetGroupMembersAsync("members", httpClient, groupId, accessToken); } - private static async Task> GetGroupMembersAsync(string groupName, HttpClient httpClient, Guid groupId, string accessToken) + private static async Task> GetGroupMembersAsync(string userType, HttpClient httpClient, Guid groupId, string accessToken) { - var results = await GraphHelper.GetResultCollectionAsync(httpClient, $"v1.0/groups/{groupId}/{groupName}", accessToken); + var results = await GraphHelper.GetResultCollectionAsync(httpClient, $"v1.0/groups/{groupId}/{userType}?$select=*", accessToken); return results; } diff --git a/src/Commands/Utilities/REST/GraphHelper.cs b/src/Commands/Utilities/REST/GraphHelper.cs index 0c6811827..734726c44 100644 --- a/src/Commands/Utilities/REST/GraphHelper.cs +++ b/src/Commands/Utilities/REST/GraphHelper.cs @@ -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; @@ -124,7 +125,8 @@ public static async Task GetAsync(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; @@ -138,7 +140,7 @@ public static async Task GetAsync(HttpClient httpClient, string url, strin var entity = JsonSerializer.Deserialize(stringContent, options); return entity; } - catch (Exception) + catch (Exception e) { return default(T); }