Skip to content

Commit ac31865

Browse files
Add groupSetting to cmdlet Get-PnPMicrosoft365GroupSettings (#4481)
* Update GetGroupSettings * Update to get group settings * Add groupsetting parameter to the cmdlet --------- Co-authored-by: Gautam Sheth <gautamdsheth@outlook.com>
1 parent 65f61bb commit ac31865

File tree

4 files changed

+137
-5
lines changed

4 files changed

+137
-5
lines changed

documentation/Get-PnPMicrosoft365GroupSettings.md

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Gets a settings of a specific Microsoft 365 Group or a tenant wide Microsoft 365
2020
## SYNTAX
2121

2222
```powershell
23-
Get-PnPMicrosoft365GroupSettings [-Identity <Microsoft365GroupPipeBind>]
23+
Get-PnPMicrosoft365GroupSettings [-Identity <Microsoft365GroupPipeBind>] [-GroupSetting <Microsoft365GroupSettingsPipeBind>]
2424
```
2525

2626
## DESCRIPTION
@@ -43,6 +43,22 @@ Get-PnPMicrosoft365GroupSettings -Identity $groupId
4343

4444
Retrieves a specific Microsoft 365 Group setting
4545

46+
47+
### EXAMPLE 3
48+
```powershell
49+
Get-PnPMicrosoft365GroupSettings -GroupSetting $groupSettingId
50+
```
51+
52+
Retrieves a tenant-wide specific Microsoft 365 Group setting.
53+
54+
55+
### EXAMPLE 4
56+
```powershell
57+
Get-PnPMicrosoft365GroupSettings -Identity $groupId -GroupSetting $groupSettingId
58+
```
59+
60+
Retrieves a group-specific Microsoft 365 Group setting
61+
4662
## PARAMETERS
4763

4864
### -Identity
@@ -59,10 +75,25 @@ Accept pipeline input: False
5975
Accept wildcard characters: False
6076
```
6177
78+
### -GroupSetting
79+
The Identity of the Microsoft 365 Group Setting
80+
81+
```yaml
82+
Type: Microsoft365GroupSettingsPipeBind
83+
Parameter Sets: (All)
84+
85+
Required: False
86+
Position: Named
87+
Default value: None
88+
Accept pipeline input: False
89+
Accept wildcard characters: False
90+
```
91+
6292
6393
## RELATED LINKS
6494
6595
[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)
66-
[Microsoft Graph documentation](https://learn.microsoft.com/graph/api/groupsetting-get)
96+
[Microsoft Graph documentation get settings](https://learn.microsoft.com/graph/api/groupsetting-get)
97+
[Microsoft Graph documentation list settings](https://learn.microsoft.com/en-gb/graph/api/group-list-setting)
6798
6899
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
using PnP.PowerShell.Commands.Model;
2+
using PnP.PowerShell.Commands.Utilities;
3+
using System;
4+
using System.Management.Automation;
5+
6+
namespace PnP.PowerShell.Commands.Base.PipeBinds
7+
{
8+
public class Microsoft365GroupSettingsPipeBind
9+
{
10+
private readonly Microsoft365GroupSetting _group;
11+
private readonly Guid _groupId;
12+
private readonly string _displayName;
13+
14+
public Microsoft365GroupSettingsPipeBind()
15+
{
16+
}
17+
18+
public Microsoft365GroupSettingsPipeBind(Microsoft365GroupSetting group)
19+
{
20+
_group = group;
21+
}
22+
23+
public Microsoft365GroupSettingsPipeBind(string input)
24+
{
25+
Guid idValue;
26+
if (Guid.TryParse(input, out idValue))
27+
{
28+
_groupId = idValue;
29+
}
30+
else
31+
{
32+
_displayName = input;
33+
}
34+
}
35+
36+
public Microsoft365GroupSettingsPipeBind(Guid guid)
37+
{
38+
_groupId = guid;
39+
}
40+
41+
public Microsoft365GroupSetting Group => _group;
42+
43+
public string DisplayName => _displayName;
44+
45+
public Guid GroupId => _groupId;
46+
47+
public Guid GetGroupSettingId(Cmdlet cmdlet, PnPConnection connection, string accessToken)
48+
{
49+
Guid idValue;
50+
if (Group != null)
51+
{
52+
Guid.TryParse(Group.Id, out idValue);
53+
return idValue;
54+
}
55+
else if (_groupId != Guid.Empty)
56+
{
57+
return _groupId;
58+
}
59+
else if (!string.IsNullOrEmpty(DisplayName))
60+
{
61+
var groups = ClearOwners.GetGroupSettings(cmdlet, connection, accessToken);
62+
if (groups != null)
63+
{
64+
var group = groups.Value.Find(p => p.DisplayName.Equals(DisplayName));
65+
if (group != null)
66+
{
67+
Guid.TryParse(group.Id, out idValue);
68+
return idValue;
69+
}
70+
}
71+
}
72+
throw new PSInvalidOperationException("Group not found");
73+
}
74+
}
75+
}

src/Commands/Microsoft365Groups/GetMicrosoft365GroupSettings.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,31 @@ public class GetMicrosoft365GroupSettings : PnPGraphCmdlet
1414
[Parameter(Mandatory = false)]
1515
public Microsoft365GroupPipeBind Identity;
1616

17+
[Parameter(Mandatory = false)]
18+
public Microsoft365GroupSettingsPipeBind GroupSetting;
19+
1720
protected override void ExecuteCmdlet()
1821
{
19-
if (Identity != null)
22+
if (Identity != null && GroupSetting != null)
23+
{
24+
var groupId = Identity.GetGroupId(this, Connection, AccessToken);
25+
var groupSettingId = GroupSetting.GetGroupSettingId(this, Connection, AccessToken);
26+
var groupSettings = ClearOwners.GetGroupSettings(this, Connection, AccessToken, groupSettingId.ToString(), groupId.ToString());
27+
WriteObject(groupSettings, true);
28+
}
29+
else if (Identity != null && GroupSetting == null)
2030
{
2131
var groupId = Identity.GetGroupId(this, Connection, AccessToken);
2232
var groupSettings = ClearOwners.GetGroupSettings(this, Connection, AccessToken, groupId.ToString());
2333
WriteObject(groupSettings?.Value, true);
2434
}
25-
else
35+
else if (Identity == null && GroupSetting != null)
36+
{
37+
var groupSettingId = GroupSetting.GetGroupSettingId(this, Connection, AccessToken);
38+
var groupSettings = ClearOwners.GetGroupTenantSettings(this, Connection, AccessToken, groupSettingId.ToString());
39+
WriteObject(groupSettings, true);
40+
}
41+
else if(Identity == null && GroupSetting == null)
2642
{
2743
var groupSettings = ClearOwners.GetGroupSettings(this, Connection, AccessToken);
2844
WriteObject(groupSettings?.Value, true);

src/Commands/Utilities/Microsoft365GroupsUtility.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,12 +713,22 @@ internal static Microsoft365GroupSettingValueCollection GetGroupSettings(Cmdlet
713713
return result;
714714
}
715715

716+
internal static Microsoft365GroupSetting GetGroupTenantSettings(Cmdlet cmdlet, PnPConnection connection, string accessToken, string groupSettingId)
717+
{
718+
var result = GraphHelper.Get<Microsoft365GroupSetting>(cmdlet, connection, $"v1.0/groupSettings/{groupSettingId}", accessToken, propertyNameCaseInsensitive: true);
719+
return result;
720+
}
721+
716722
internal static Microsoft365GroupSettingValueCollection GetGroupSettings(Cmdlet cmdlet, PnPConnection connection, string accessToken, string groupId)
717723
{
718724
var result = GraphHelper.Get<Microsoft365GroupSettingValueCollection>(cmdlet, connection, $"v1.0/groups/{groupId}/settings", accessToken, propertyNameCaseInsensitive: true);
719725
return result;
720726
}
721-
727+
internal static Microsoft365GroupSetting GetGroupSettings(Cmdlet cmdlet, PnPConnection connection, string accessToken, string groupSettingId, string groupId)
728+
{
729+
var result = GraphHelper.Get<Microsoft365GroupSetting>(cmdlet, connection, $"v1.0/groups/{groupId}/settings/{groupSettingId}", accessToken, propertyNameCaseInsensitive: true);
730+
return result;
731+
}
722732
internal static Microsoft365GroupSetting CreateGroupSetting(Cmdlet cmdlet, PnPConnection connection, string accessToken, dynamic groupSettingObject)
723733
{
724734
var stringContent = new StringContent(JsonSerializer.Serialize(groupSettingObject));

0 commit comments

Comments
 (0)