Skip to content
This repository was archived by the owner on Jan 19, 2021. It is now read-only.

Commit 398c994

Browse files
authored
Merge pull request #791 from wobba/OptimizeGraphQueriesWithExcludeDrive
Optimize graph queries with exclude drive
2 parents 5e65023 + 9313486 commit 398c994

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

Commands/Graph/GetUnifiedGroup.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ namespace SharePointPnP.PowerShell.Commands.Graph
2929
Remarks = "Retrieves a specific Office 365 Group based on its DisplayName",
3030
SortOrder = 3)]
3131
[CmdletExample(
32-
Code = "PS:> Get-PnPUnifiedGroup -Identity $groupSiteUrl",
33-
Remarks = "Retrieves a specific Office 365 Group based on the URL of its Modern SharePoint site",
32+
Code = "PS:> Get-PnPUnifiedGroup -Identity $groupSiteMailNickName",
33+
Remarks = "Retrieves a specific Office 365 Group based on the mail nickname",
3434
SortOrder = 4)]
3535
[CmdletExample(
3636
Code = "PS:> Get-PnPUnifiedGroup -Identity $group",
@@ -41,6 +41,9 @@ public class GetUnifiedGroup : PnPGraphCmdlet
4141
[Parameter(Mandatory = false, HelpMessage = "The Identity of the Office 365 Group.")]
4242
public UnifiedGroupPipeBind Identity;
4343

44+
[Parameter(Mandatory = false, HelpMessage = "Exclude fetching the site URL for Office 365 Groups. This speeds up large listings.")]
45+
public SwitchParameter ExcludeSiteUrl;
46+
4447
protected override void ExecuteCmdlet()
4548
{
4649
UnifiedGroupEntity group = null;
@@ -51,21 +54,25 @@ protected override void ExecuteCmdlet()
5154
// We have to retrieve a specific group
5255
if (Identity.Group != null)
5356
{
54-
group = UnifiedGroupsUtility.GetUnifiedGroup(Identity.Group.GroupId, AccessToken);
57+
group = UnifiedGroupsUtility.GetUnifiedGroup(Identity.Group.GroupId, AccessToken, includeSite: !ExcludeSiteUrl.IsPresent);
5558
}
5659
else if (!String.IsNullOrEmpty(Identity.DisplayName))
5760
{
58-
groups = UnifiedGroupsUtility.ListUnifiedGroups(AccessToken, Identity.DisplayName);
61+
groups = UnifiedGroupsUtility.ListUnifiedGroups(AccessToken, Identity.DisplayName, includeSite: !ExcludeSiteUrl.IsPresent);
62+
if (groups == null || groups.Count == 0)
63+
{
64+
groups = UnifiedGroupsUtility.ListUnifiedGroups(AccessToken, mailNickname: Identity.DisplayName, includeSite: !ExcludeSiteUrl.IsPresent);
65+
}
5966
}
6067
else if (!String.IsNullOrEmpty(Identity.GroupId))
6168
{
62-
group = UnifiedGroupsUtility.GetUnifiedGroup(Identity.GroupId, AccessToken);
69+
group = UnifiedGroupsUtility.GetUnifiedGroup(Identity.GroupId, AccessToken, includeSite: !ExcludeSiteUrl.IsPresent);
6370
}
6471
}
6572
else
6673
{
6774
// Retrieve all the groups
68-
groups = UnifiedGroupsUtility.ListUnifiedGroups(AccessToken);
75+
groups = UnifiedGroupsUtility.ListUnifiedGroups(AccessToken, includeSite: !ExcludeSiteUrl.IsPresent);
6976
}
7077

7178
if (group != null)

Commands/Graph/RemoveUnifiedGroup.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ protected override void ExecuteCmdlet()
3838
// We have to retrieve a specific group
3939
if (Identity.Group != null)
4040
{
41-
group = UnifiedGroupsUtility.GetUnifiedGroup(Identity.Group.GroupId, AccessToken);
41+
group = UnifiedGroupsUtility.GetUnifiedGroup(Identity.Group.GroupId, AccessToken, includeSite: false);
4242
}
4343
else if (!String.IsNullOrEmpty(Identity.GroupId))
4444
{
45-
group = UnifiedGroupsUtility.GetUnifiedGroup(Identity.GroupId, AccessToken);
45+
group = UnifiedGroupsUtility.GetUnifiedGroup(Identity.GroupId, AccessToken, includeSite: false);
4646
}
4747

4848
if (group != null)

0 commit comments

Comments
 (0)