Skip to content

Commit

Permalink
Add groupsetting parameter to the cmdlet
Browse files Browse the repository at this point in the history
  • Loading branch information
reshmee011 committed Oct 27, 2024
1 parent 0d44d48 commit 8f67469
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 20 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)
14 changes: 10 additions & 4 deletions src/Commands/Base/PipeBinds/Microsoft365GroupSettingsPipeBind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,17 @@ public Microsoft365GroupSettingsPipeBind(Guid guid)

public Microsoft365GroupSetting Group => _group;

public String DisplayName => _displayName;
public string DisplayName => _displayName;

public Guid GroupId => _groupId;

public Guid GetGroupSettingId(Cmdlet cmdlet, PnPConnection connection, string accessToken)
{
Guid idValue;
if (Group != null)
{
return _group.Id.Value;
Guid.TryParse(Group.Id, out idValue);
return idValue;
}
else if (_groupId != Guid.Empty)
{
Expand All @@ -59,8 +61,12 @@ public Guid GetGroupSettingId(Cmdlet cmdlet, PnPConnection connection, string ac
var groups = ClearOwners.GetGroupSettings(cmdlet, connection, accessToken);
if (groups != null)
{
var collection = groups.Where(p => p.displayName.Equals(displayName));
return group.Id.Value;
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");
Expand Down
26 changes: 17 additions & 9 deletions src/Commands/Microsoft365Groups/GetMicrosoft365GroupSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,33 @@ namespace PnP.PowerShell.Commands.Microsoft365Groups
public class GetMicrosoft365GroupSettings : PnPGraphCmdlet
{
[Parameter(Mandatory = false)]
public Microsoft365GroupPipeBind Group;
public Microsoft365GroupPipeBind Identity;

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

protected override void ExecuteCmdlet()
{
if (Identity != null && Group !=null)
if (Identity != null && GroupSetting != null)
{
var groupId = Group.GetGroupId(this, Connection, AccessToken);
var groupSettings = ClearOwners.GetGroupSettings(this, Connection, AccessToken,Identity.Id.ToString ,groupId.ToString());
WriteObject(groupSettings?.Value, true);
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);
}
elseif(Identity != null && Group == null)
else if (Identity != null && GroupSetting == null)
{
var groupSettings = ClearOwners.GetGroupSettings(this, Connection, AccessToken,Identity.Id.ToString());
var groupId = Identity.GetGroupId(this, Connection, AccessToken);
var groupSettings = ClearOwners.GetGroupSettings(this, Connection, AccessToken, groupId.ToString());
WriteObject(groupSettings?.Value, true);
}
elseif(Identity == null && Group ==null)
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
14 changes: 9 additions & 5 deletions src/Commands/Utilities/Microsoft365GroupsUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -713,18 +713,22 @@ internal static Microsoft365GroupSettingValueCollection GetGroupSettings(Cmdlet
return result;
}

internal static Microsoft365GroupSettingValueCollection GetGroupTenantSettings(Cmdlet cmdlet, PnPConnection connection, string accessToken, string groupSettingId)
internal static Microsoft365GroupSetting GetGroupTenantSettings(Cmdlet cmdlet, PnPConnection connection, string accessToken, string groupSettingId)
{
var result = GraphHelper.Get<Microsoft365GroupSettingValueCollection>(cmdlet, connection, $"v1.0/groupSettings/{groupSettingId}", accessToken, propertyNameCaseInsensitive: true);
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 groupSettingId,string groupId)
internal static Microsoft365GroupSettingValueCollection GetGroupSettings(Cmdlet cmdlet, PnPConnection connection, string accessToken, string groupId)
{
var result = GraphHelper.Get<Microsoft365GroupSettingValueCollection>(cmdlet, connection, $"v1.0/groups/{groupId}/settings/{groupSettingId}", accessToken, propertyNameCaseInsensitive: true);
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 8f67469

Please sign in to comment.