Skip to content

Commit ffa67d4

Browse files
committed
fix: standardize variable casing and return more groupInfo for single groups
1 parent 6ac1879 commit ffa67d4

File tree

1 file changed

+22
-30
lines changed

1 file changed

+22
-30
lines changed

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

Lines changed: 22 additions & 30 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,40 +86,32 @@ 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-
101-
if ($_.mailEnabled -and $_.securityEnabled) {
102-
'Mail-Enabled Security'
103-
}
104-
if (!$_.mailEnabled -and $_.securityEnabled) {
105-
'Security'
106-
}
107-
if ($_.groupTypes -contains 'Unified') {
108-
'Microsoft 365'
109-
}
110-
if (([string]::isNullOrEmpty($_.groupTypes)) -and ($_.mailEnabled) -and (!$_.securityEnabled)) {
111-
'Distribution List'
112-
}
108+
if ($_.mailEnabled -and $_.securityEnabled) { 'Mail-Enabled Security' }
109+
if (!$_.mailEnabled -and $_.securityEnabled) { 'Security' }
110+
if ($_.groupTypes -contains 'Unified') { 'Microsoft 365' }
111+
if (([string]::isNullOrEmpty($_.groupTypes)) -and ($_.mailEnabled) -and (!$_.securityEnabled)) { 'Distribution List' }
113112
}
114113
},
115-
@{Name = 'dynamicGroupBool'; Expression = {
116-
if ($_.groupTypes -contains 'DynamicMembership') {
117-
$true
118-
} else {
119-
$false
120-
}
121-
}
122-
}
114+
@{Name = 'dynamicGroupBool'; Expression = { if ($_.groupTypes -contains 'DynamicMembership') { $true } else { $false } } }
123115
$GraphRequest = @($GraphRequest | Sort-Object displayName)
124116
}
125117

0 commit comments

Comments
 (0)