Skip to content

Commit

Permalink
Add groupSetting to cmdlet Get-PnPMicrosoft365GroupSettings (#4481)
Browse files Browse the repository at this point in the history
* Update GetGroupSettings

* Update to get group settings

* Add groupsetting parameter to the cmdlet

---------

Co-authored-by: Gautam Sheth <[email protected]>
  • Loading branch information
reshmee011 and gautamdsheth authored Oct 28, 2024
1 parent 65f61bb commit ac31865
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 5 deletions.
35 changes: 33 additions & 2 deletions documentation/Get-PnPMicrosoft365GroupSettings.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Gets a settings of a specific Microsoft 365 Group or a tenant wide Microsoft 365
## SYNTAX

```powershell
Get-PnPMicrosoft365GroupSettings [-Identity <Microsoft365GroupPipeBind>]
Get-PnPMicrosoft365GroupSettings [-Identity <Microsoft365GroupPipeBind>] [-GroupSetting <Microsoft365GroupSettingsPipeBind>]
```

## DESCRIPTION
Expand All @@ -43,6 +43,22 @@ Get-PnPMicrosoft365GroupSettings -Identity $groupId

Retrieves a specific Microsoft 365 Group setting


### EXAMPLE 3
```powershell
Get-PnPMicrosoft365GroupSettings -GroupSetting $groupSettingId
```

Retrieves a tenant-wide specific Microsoft 365 Group setting.


### EXAMPLE 4
```powershell
Get-PnPMicrosoft365GroupSettings -Identity $groupId -GroupSetting $groupSettingId
```

Retrieves a group-specific Microsoft 365 Group setting

## PARAMETERS

### -Identity
Expand All @@ -59,10 +75,25 @@ Accept pipeline input: False
Accept wildcard characters: False
```
### -GroupSetting
The Identity of the Microsoft 365 Group Setting
```yaml
Type: Microsoft365GroupSettingsPipeBind
Parameter Sets: (All)

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```
## RELATED LINKS
[Microsoft 365 Patterns and Practices](https://aka.ms/m365pnp)
[Microsoft Graph documentation](https://learn.microsoft.com/graph/api/groupsetting-get)
[Microsoft Graph documentation get settings](https://learn.microsoft.com/graph/api/groupsetting-get)
[Microsoft Graph documentation list settings](https://learn.microsoft.com/en-gb/graph/api/group-list-setting)
75 changes: 75 additions & 0 deletions src/Commands/Base/PipeBinds/Microsoft365GroupSettingsPipeBind.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
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)
{
Guid idValue;
if (Group != null)
{
Guid.TryParse(Group.Id, out idValue);
return idValue;
}
else if (_groupId != Guid.Empty)
{
return _groupId;
}
else if (!string.IsNullOrEmpty(DisplayName))
{
var groups = ClearOwners.GetGroupSettings(cmdlet, connection, accessToken);
if (groups != null)
{
var group = groups.Value.Find(p => p.DisplayName.Equals(DisplayName));
if (group != null)
{
Guid.TryParse(group.Id, out idValue);
return idValue;
}
}
}
throw new PSInvalidOperationException("Group not found");
}
}
}
20 changes: 18 additions & 2 deletions src/Commands/Microsoft365Groups/GetMicrosoft365GroupSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,31 @@ public class GetMicrosoft365GroupSettings : PnPGraphCmdlet
[Parameter(Mandatory = false)]
public Microsoft365GroupPipeBind Identity;

[Parameter(Mandatory = false)]
public Microsoft365GroupSettingsPipeBind GroupSetting;

protected override void ExecuteCmdlet()
{
if (Identity != null)
if (Identity != null && GroupSetting != null)
{
var groupId = Identity.GetGroupId(this, Connection, AccessToken);
var groupSettingId = GroupSetting.GetGroupSettingId(this, Connection, AccessToken);
var groupSettings = ClearOwners.GetGroupSettings(this, Connection, AccessToken, groupSettingId.ToString(), groupId.ToString());
WriteObject(groupSettings, true);
}
else if (Identity != null && GroupSetting == null)
{
var groupId = Identity.GetGroupId(this, Connection, AccessToken);
var groupSettings = ClearOwners.GetGroupSettings(this, Connection, AccessToken, groupId.ToString());
WriteObject(groupSettings?.Value, true);
}
else
else if (Identity == null && GroupSetting != null)
{
var groupSettingId = GroupSetting.GetGroupSettingId(this, Connection, AccessToken);
var groupSettings = ClearOwners.GetGroupTenantSettings(this, Connection, AccessToken, groupSettingId.ToString());
WriteObject(groupSettings, true);
}
else if(Identity == null && GroupSetting == null)
{
var groupSettings = ClearOwners.GetGroupSettings(this, Connection, AccessToken);
WriteObject(groupSettings?.Value, true);
Expand Down
12 changes: 11 additions & 1 deletion src/Commands/Utilities/Microsoft365GroupsUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -713,12 +713,22 @@ internal static Microsoft365GroupSettingValueCollection GetGroupSettings(Cmdlet
return result;
}

internal static Microsoft365GroupSetting GetGroupTenantSettings(Cmdlet cmdlet, PnPConnection connection, string accessToken, string groupSettingId)
{
var result = GraphHelper.Get<Microsoft365GroupSetting>(cmdlet, connection, $"v1.0/groupSettings/{groupSettingId}", accessToken, propertyNameCaseInsensitive: true);
return result;
}

internal static Microsoft365GroupSettingValueCollection GetGroupSettings(Cmdlet cmdlet, PnPConnection connection, string accessToken, string groupId)
{
var result = GraphHelper.Get<Microsoft365GroupSettingValueCollection>(cmdlet, connection, $"v1.0/groups/{groupId}/settings", accessToken, propertyNameCaseInsensitive: true);
return result;
}

internal static Microsoft365GroupSetting GetGroupSettings(Cmdlet cmdlet, PnPConnection connection, string accessToken, string groupSettingId, string groupId)
{
var result = GraphHelper.Get<Microsoft365GroupSetting>(cmdlet, connection, $"v1.0/groups/{groupId}/settings/{groupSettingId}", accessToken, propertyNameCaseInsensitive: true);
return result;
}
internal static Microsoft365GroupSetting CreateGroupSetting(Cmdlet cmdlet, PnPConnection connection, string accessToken, dynamic groupSettingObject)
{
var stringContent = new StringContent(JsonSerializer.Serialize(groupSettingObject));
Expand Down

0 comments on commit ac31865

Please sign in to comment.