Skip to content

Commit e3c423d

Browse files
Merge branch 'dev' of https://github.com/KelvinTegelaar/CIPP-API into dev
2 parents 7fe5d5c + 56db9be commit e3c423d

File tree

1 file changed

+23
-28
lines changed

1 file changed

+23
-28
lines changed

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Identity/Administration/Groups/Invoke-ListGroups.ps1

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,34 +15,34 @@ function Invoke-ListGroups {
1515
Write-LogMessage -headers $Headers -API $APIName -message 'Accessed this API' -Sev 'Debug'
1616

1717
$TenantFilter = $Request.Query.TenantFilter
18-
$selectstring = "id,createdDateTime,displayName,description,mail,mailEnabled,mailNickname,resourceProvisioningOptions,securityEnabled,visibility,organizationId,onPremisesSamAccountName,membershipRule,grouptypes,onPremisesSyncEnabled,resourceProvisioningOptions,userPrincipalName&`$expand=members(`$select=userPrincipalName)"
18+
$SelectString = 'id,createdDateTime,displayName,description,mail,mailEnabled,mailNickname,resourceProvisioningOptions,securityEnabled,visibility,organizationId,onPremisesSamAccountName,membershipRule,groupTypes,onPremisesSyncEnabled,resourceProvisioningOptions,userPrincipalName&$expand=members($select=userPrincipalName)'
1919

2020
$BulkRequestArrayList = [System.Collections.Generic.List[object]]::new()
2121

2222
if ($Request.Query.GroupID) {
23-
$selectstring = 'id,createdDateTime,displayName,description,mail,mailEnabled,mailNickname,resourceProvisioningOptions,securityEnabled,visibility,organizationId,onPremisesSamAccountName,membershipRule,groupTypes,userPrincipalName'
23+
$SelectString = 'id,createdDateTime,displayName,description,mail,mailEnabled,mailNickname,resourceProvisioningOptions,securityEnabled,visibility,organizationId,onPremisesSamAccountName,membershipRule,groupTypes,userPrincipalName'
2424
$BulkRequestArrayList.add(@{
2525
id = 1
2626
method = 'GET'
27-
url = "groups/$($Request.Query.GroupID)?`$select=$selectstring"
27+
url = "groups/$($Request.Query.GroupID)?`$select=$SelectString"
2828
})
2929
}
3030
if ($Request.Query.members) {
31-
$selectstring = 'id,userPrincipalName,displayName,hideFromOutlookClients,hideFromAddressLists,mail,mailEnabled,mailNickname,resourceProvisioningOptions,securityEnabled,visibility,organizationId,onPremisesSamAccountName,membershipRule'
31+
$SelectString = 'id,userPrincipalName,displayName,hideFromOutlookClients,hideFromAddressLists,mail,mailEnabled,mailNickname,resourceProvisioningOptions,securityEnabled,visibility,organizationId,onPremisesSamAccountName,membershipRule'
3232
$BulkRequestArrayList.add(@{
3333
id = 2
3434
method = 'GET'
35-
url = "groups/$($Request.Query.GroupID)/members?`$top=999&select=$selectstring"
35+
url = "groups/$($Request.Query.GroupID)/members?`$top=999&select=$SelectString"
3636
})
3737
}
3838

3939
if ($Request.Query.owners) {
4040
if ($Request.Query.groupType -ne 'Distribution List' -and $Request.Query.groupType -ne 'Mail-Enabled Security') {
41-
$selectstring = 'id,userPrincipalName,displayName,hideFromOutlookClients,hideFromAddressLists,mail,mailEnabled,mailNickname,resourceProvisioningOptions,securityEnabled,visibility,organizationId,onPremisesSamAccountName,membershipRule'
41+
$SelectString = 'id,userPrincipalName,displayName,hideFromOutlookClients,hideFromAddressLists,mail,mailEnabled,mailNickname,resourceProvisioningOptions,securityEnabled,visibility,organizationId,onPremisesSamAccountName,membershipRule'
4242
$BulkRequestArrayList.add(@{
4343
id = 3
4444
method = 'GET'
45-
url = "groups/$($Request.Query.GroupID)/owners?`$top=999&select=$selectstring"
45+
url = "groups/$($Request.Query.GroupID)/owners?`$top=999&select=$SelectString"
4646
})
4747
} else {
4848
$OwnerIds = New-ExoRequest -cmdlet 'Get-DistributionGroup' -tenantid $TenantFilter -cmdParams @{Identity = $Request.Query.GroupID } -useSystemMailbox $true | Select-Object -ExpandProperty ManagedBy
@@ -86,38 +86,33 @@ function Invoke-ListGroups {
8686
if ($BulkRequestArrayList.Count -gt 0) {
8787
$RawGraphRequest = New-GraphBulkRequest -tenantid $TenantFilter -scope 'https://graph.microsoft.com/.default' -Requests @($BulkRequestArrayList) -asapp $true
8888
$GraphRequest = [PSCustomObject]@{
89-
groupInfo = ($RawGraphRequest | Where-Object { $_.id -eq 1 }).body
89+
groupInfo = ($RawGraphRequest | Where-Object { $_.id -eq 1 }).body | Select-Object *, @{ Name = 'primDomain'; Expression = { $_.mail -split '@' | Select-Object -Last 1 } },
90+
@{Name = 'teamsEnabled'; Expression = { if ($_.resourceProvisioningOptions -Like '*Team*') { $true } else { $false } } },
91+
@{Name = 'calculatedGroupType'; Expression = {
92+
if ($_.mailEnabled -and $_.securityEnabled) { 'Mail-Enabled Security' }
93+
if (!$_.mailEnabled -and $_.securityEnabled) { 'Security' }
94+
if ($_.groupTypes -contains 'Unified') { 'Microsoft 365' }
95+
if (([string]::isNullOrEmpty($_.groupTypes)) -and ($_.mailEnabled) -and (!$_.securityEnabled)) { 'Distribution List' }
96+
}
97+
}, @{Name = 'dynamicGroupBool'; Expression = { if ($_.groupTypes -contains 'DynamicMembership') { $true } else { $false } } }
9098
members = ($RawGraphRequest | Where-Object { $_.id -eq 2 }).body.value
9199
owners = ($RawGraphRequest | Where-Object { $_.id -eq 3 }).body.value
92100
allowExternal = (!$OnlyAllowInternal)
93101
sendCopies = $SendCopies
94102
}
95103
} else {
96-
$GraphRequest = New-GraphGetRequest -uri "https://graph.microsoft.com/beta/groups/$($GroupID)/$($members)?`$top=999&select=$selectstring" -tenantid $TenantFilter | Select-Object *, @{ Name = 'primDomain'; Expression = { $_.mail -split '@' | Select-Object -Last 1 } },
104+
$GraphRequest = New-GraphGetRequest -uri "https://graph.microsoft.com/beta/groups/$($GroupID)/$($members)?`$top=999&select=$SelectString" -tenantid $TenantFilter | Select-Object *, @{ Name = 'primDomain'; Expression = { $_.mail -split '@' | Select-Object -Last 1 } },
97105
@{Name = 'membersCsv'; Expression = { $_.members.userPrincipalName -join ',' } },
98106
@{Name = 'teamsEnabled'; Expression = { if ($_.resourceProvisioningOptions -like '*Team*') { $true }else { $false } } },
99107
@{Name = 'calculatedGroupType'; Expression = {
100-
if ($_.groupTypes -contains 'Unified') {
101-
'Microsoft 365'
102-
} elseif ($_.mailEnabled -and $_.securityEnabled) {
103-
'Mail-Enabled Security'
104-
}
105-
if (!$_.mailEnabled -and $_.securityEnabled) {
106-
'Security'
107-
}
108-
if (([string]::isNullOrEmpty($_.groupTypes)) -and ($_.mailEnabled) -and (!$_.securityEnabled)) {
109-
'Distribution List'
110-
}
108+
109+
if ($_.mailEnabled -and $_.securityEnabled) { 'Mail-Enabled Security' }
110+
if (!$_.mailEnabled -and $_.securityEnabled) { 'Security' }
111+
if ($_.groupTypes -contains 'Unified') { 'Microsoft 365' }
112+
if (([string]::isNullOrEmpty($_.groupTypes)) -and ($_.mailEnabled) -and (!$_.securityEnabled)) { 'Distribution List' }
111113
}
112114
},
113-
@{Name = 'dynamicGroupBool'; Expression = {
114-
if ($_.groupTypes -contains 'DynamicMembership') {
115-
$true
116-
} else {
117-
$false
118-
}
119-
}
120-
}
115+
@{Name = 'dynamicGroupBool'; Expression = { if ($_.groupTypes -contains 'DynamicMembership') { $true } else { $false } } }
121116
$GraphRequest = @($GraphRequest | Sort-Object displayName)
122117
}
123118

0 commit comments

Comments
 (0)