From 50fd83bc4b83d96209ce8b6cb025bdf65b6dbe0e Mon Sep 17 00:00:00 2001 From: Milan Holemans <11723921+milanholemans@users.noreply.github.com> Date: Sat, 21 Dec 2024 17:51:31 +0100 Subject: [PATCH] Fixes retrieving distribution groups. Closes #6529 --- src/m365/entra/commands/group/group-list.spec.ts | 2 +- src/m365/entra/commands/group/group-list.ts | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/m365/entra/commands/group/group-list.spec.ts b/src/m365/entra/commands/group/group-list.spec.ts index 485c4612cc6..72582540028 100644 --- a/src/m365/entra/commands/group/group-list.spec.ts +++ b/src/m365/entra/commands/group/group-list.spec.ts @@ -368,7 +368,7 @@ describe(commands.GROUP_LIST, () => { it('lists all distribution groups in the tenant', async () => { sinon.stub(request, 'get').callsFake(async (opts) => { - if (opts.url === `https://graph.microsoft.com/v1.0/groups?$filter=securityEnabled eq false and mailEnabled eq true`) { + if (opts.url === `https://graph.microsoft.com/v1.0/groups?$filter=securityEnabled eq false and mailEnabled eq true and not(groupTypes/any(t:t eq 'Unified'))&$count=true`) { return { "value": [ { diff --git a/src/m365/entra/commands/group/group-list.ts b/src/m365/entra/commands/group/group-list.ts index 95e7ce0bcf1..c49c0cbbfd4 100644 --- a/src/m365/entra/commands/group/group-list.ts +++ b/src/m365/entra/commands/group/group-list.ts @@ -92,7 +92,8 @@ class EntraGroupListCommand extends GraphCommand { requestUrl += '?$filter=securityEnabled eq true and mailEnabled eq false'; break; case 'distribution': - requestUrl += '?$filter=securityEnabled eq false and mailEnabled eq true'; + useConsistencyLevelHeader = true; + requestUrl += `?$filter=securityEnabled eq false and mailEnabled eq true and not(groupTypes/any(t:t eq 'Unified'))&$count=true`; break; case 'mailEnabledSecurity': useConsistencyLevelHeader = true; @@ -139,7 +140,7 @@ class EntraGroupListCommand extends GraphCommand { if (cli.shouldTrimOutput(args.options.output)) { groups.forEach((group: ExtendedGroup) => { - if (group.groupTypes && group.groupTypes.length > 0 && group.groupTypes[0] === 'Unified') { + if (group.groupTypes && group.groupTypes.length > 0 && group.groupTypes.includes('Unified')) { group.groupType = 'Microsoft 365'; } else if (group.mailEnabled && group.securityEnabled) {