From d78b30ddf7a5ad0bd0a2075199948280d2e7b2a7 Mon Sep 17 00:00:00 2001 From: Reshmee Auckloo Date: Fri, 25 Oct 2024 19:52:39 +0100 Subject: [PATCH 1/2] Update GetGroupSettings --- src/Commands/Utilities/Microsoft365GroupsUtility.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Commands/Utilities/Microsoft365GroupsUtility.cs b/src/Commands/Utilities/Microsoft365GroupsUtility.cs index 21f16d1aa..ec340a99d 100644 --- a/src/Commands/Utilities/Microsoft365GroupsUtility.cs +++ b/src/Commands/Utilities/Microsoft365GroupsUtility.cs @@ -715,7 +715,7 @@ internal static Microsoft365GroupSettingValueCollection GetGroupSettings(Cmdlet internal static Microsoft365GroupSettingValueCollection GetGroupSettings(Cmdlet cmdlet, PnPConnection connection, string accessToken, string groupId) { - var result = GraphHelper.Get(cmdlet, connection, $"v1.0/groups/{groupId}/settings", accessToken, propertyNameCaseInsensitive: true); + var result = GraphHelper.Get(cmdlet, connection, $"v1.0/groupSettings/{groupId}", accessToken, propertyNameCaseInsensitive: true); return result; } From 0d44d48023566f15c22e80967b6b555185428470 Mon Sep 17 00:00:00 2001 From: Reshmee Auckloo Date: Fri, 25 Oct 2024 20:23:20 +0100 Subject: [PATCH 2/2] Update to get group settings --- .../Microsoft365GroupSettingsPipeBind.cs | 69 +++++++++++++++++++ .../GetMicrosoft365GroupSettings.cs | 18 +++-- .../Utilities/Microsoft365GroupsUtility.cs | 10 ++- 3 files changed, 90 insertions(+), 7 deletions(-) create mode 100644 src/Commands/Base/PipeBinds/Microsoft365GroupSettingsPipeBind.cs diff --git a/src/Commands/Base/PipeBinds/Microsoft365GroupSettingsPipeBind.cs b/src/Commands/Base/PipeBinds/Microsoft365GroupSettingsPipeBind.cs new file mode 100644 index 000000000..58723e31e --- /dev/null +++ b/src/Commands/Base/PipeBinds/Microsoft365GroupSettingsPipeBind.cs @@ -0,0 +1,69 @@ +using PnP.PowerShell.Commands.Model; +using PnP.PowerShell.Commands.Utilities; +using System; +using System.Management.Automation; + +namespace PnP.PowerShell.Commands.Base.PipeBinds +{ + public class Microsoft365GroupSettingsPipeBind + { + private readonly Microsoft365GroupSetting _group; + private readonly Guid _groupId; + private readonly string _displayName; + + public Microsoft365GroupSettingsPipeBind() + { + } + + public Microsoft365GroupSettingsPipeBind(Microsoft365GroupSetting group) + { + _group = group; + } + + public Microsoft365GroupSettingsPipeBind(string input) + { + Guid idValue; + if (Guid.TryParse(input, out idValue)) + { + _groupId = idValue; + } + else + { + _displayName = input; + } + } + + public Microsoft365GroupSettingsPipeBind(Guid guid) + { + _groupId = guid; + } + + public Microsoft365GroupSetting Group => _group; + + public String DisplayName => _displayName; + + public Guid GroupId => _groupId; + + public Guid GetGroupSettingId(Cmdlet cmdlet, PnPConnection connection, string accessToken) + { + if (Group != null) + { + return _group.Id.Value; + } + else if (_groupId != Guid.Empty) + { + return _groupId; + } + else if (!string.IsNullOrEmpty(DisplayName)) + { + var groups = ClearOwners.GetGroupSettings(cmdlet, connection, accessToken); + if (groups != null) + { + var collection = groups.Where(p => p.displayName.Equals(displayName)); + return group.Id.Value; + } + } + throw new PSInvalidOperationException("Group not found"); + } + } +} diff --git a/src/Commands/Microsoft365Groups/GetMicrosoft365GroupSettings.cs b/src/Commands/Microsoft365Groups/GetMicrosoft365GroupSettings.cs index 520fd3922..8230349c5 100644 --- a/src/Commands/Microsoft365Groups/GetMicrosoft365GroupSettings.cs +++ b/src/Commands/Microsoft365Groups/GetMicrosoft365GroupSettings.cs @@ -12,17 +12,25 @@ namespace PnP.PowerShell.Commands.Microsoft365Groups public class GetMicrosoft365GroupSettings : PnPGraphCmdlet { [Parameter(Mandatory = false)] - public Microsoft365GroupPipeBind Identity; + public Microsoft365GroupPipeBind Group; + + [Parameter(Mandatory = false)] + public Microsoft365GroupSettingsPipeBind Identity; protected override void ExecuteCmdlet() { - if (Identity != null) + if (Identity != null && Group !=null) + { + var groupId = Group.GetGroupId(this, Connection, AccessToken); + var groupSettings = ClearOwners.GetGroupSettings(this, Connection, AccessToken,Identity.Id.ToString ,groupId.ToString()); + WriteObject(groupSettings?.Value, true); + } + elseif(Identity != null && Group == null) { - var groupId = Identity.GetGroupId(this, Connection, AccessToken); - var groupSettings = ClearOwners.GetGroupSettings(this, Connection, AccessToken, groupId.ToString()); + var groupSettings = ClearOwners.GetGroupSettings(this, Connection, AccessToken,Identity.Id.ToString()); WriteObject(groupSettings?.Value, true); } - else + elseif(Identity == null && Group ==null) { var groupSettings = ClearOwners.GetGroupSettings(this, Connection, AccessToken); WriteObject(groupSettings?.Value, true); diff --git a/src/Commands/Utilities/Microsoft365GroupsUtility.cs b/src/Commands/Utilities/Microsoft365GroupsUtility.cs index ec340a99d..5b9c37745 100644 --- a/src/Commands/Utilities/Microsoft365GroupsUtility.cs +++ b/src/Commands/Utilities/Microsoft365GroupsUtility.cs @@ -713,9 +713,15 @@ internal static Microsoft365GroupSettingValueCollection GetGroupSettings(Cmdlet return result; } - internal static Microsoft365GroupSettingValueCollection GetGroupSettings(Cmdlet cmdlet, PnPConnection connection, string accessToken, string groupId) + internal static Microsoft365GroupSettingValueCollection GetGroupTenantSettings(Cmdlet cmdlet, PnPConnection connection, string accessToken, string groupSettingId) { - var result = GraphHelper.Get(cmdlet, connection, $"v1.0/groupSettings/{groupId}", accessToken, propertyNameCaseInsensitive: true); + var result = GraphHelper.Get(cmdlet, connection, $"v1.0/groupSettings/{groupSettingId}", accessToken, propertyNameCaseInsensitive: true); + return result; + } + + internal static Microsoft365GroupSettingValueCollection GetGroupSettings(Cmdlet cmdlet, PnPConnection connection, string accessToken, string groupSettingId,string groupId) + { + var result = GraphHelper.Get(cmdlet, connection, $"v1.0/groups/{groupId}/settings/{groupSettingId}", accessToken, propertyNameCaseInsensitive: true); return result; }