Skip to content

Commit 36af8d4

Browse files
committed
fix group management
fixes KelvinTegelaar/CIPP#4882
1 parent 818991a commit 36af8d4

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function Invoke-AddGroupTemplate {
2929
'*unified*' { 'm365'; break }
3030
'*m365*' { 'm365'; break }
3131
'*generic*' { 'generic'; break }
32-
'*security*' { 'generic'; break }
32+
'*security*' { 'security'; break }
3333
'*distribution*' { 'distribution'; break }
3434
'*mail*' { 'distribution'; break }
3535
default { $Request.Body.groupType }

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,21 @@ function Invoke-ListGroups {
8787
$GraphRequest = [PSCustomObject]@{
8888
groupInfo = ($RawGraphRequest | Where-Object { $_.id -eq 1 }).body | Select-Object *, @{ Name = 'primDomain'; Expression = { $_.mail -split '@' | Select-Object -Last 1 } },
8989
@{Name = 'teamsEnabled'; Expression = { if ($_.resourceProvisioningOptions -like '*Team*') { $true } else { $false } } },
90-
@{Name = 'calculatedGroupType'; Expression = {
90+
@{Name = 'groupType'; Expression = {
9191
if ($_.groupTypes -contains 'Unified') { 'Microsoft 365' }
9292
elseif ($_.mailEnabled -and $_.securityEnabled) { 'Mail-Enabled Security' }
9393
elseif (-not $_.mailEnabled -and $_.securityEnabled) { 'Security' }
9494
elseif (([string]::isNullOrEmpty($_.groupTypes)) -and ($_.mailEnabled) -and (-not $_.securityEnabled)) { 'Distribution List' }
9595
}
96-
}, @{Name = 'dynamicGroupBool'; Expression = { if ($_.groupTypes -contains 'DynamicMembership') { $true } else { $false } } }
96+
},
97+
@{Name = 'calculatedGroupType'; Expression = {
98+
if ($_.groupTypes -contains 'Unified') { 'm365' }
99+
elseif ($_.mailEnabled -and $_.securityEnabled) { 'security' }
100+
elseif (-not $_.mailEnabled -and $_.securityEnabled) { 'generic' }
101+
elseif (([string]::isNullOrEmpty($_.groupTypes)) -and ($_.mailEnabled) -and (-not $_.securityEnabled)) { 'distributionList' }
102+
}
103+
},
104+
@{Name = 'dynamicGroupBool'; Expression = { if ($_.groupTypes -contains 'DynamicMembership') { $true } else { $false } } }
97105
members = ($RawGraphRequest | Where-Object { $_.id -eq 2 }).body.value
98106
owners = ($RawGraphRequest | Where-Object { $_.id -eq 3 }).body.value
99107
allowExternal = (!$OnlyAllowInternal)
@@ -104,13 +112,20 @@ function Invoke-ListGroups {
104112
$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 } },
105113
@{Name = 'membersCsv'; Expression = { $_.members.userPrincipalName -join ',' } },
106114
@{Name = 'teamsEnabled'; Expression = { if ($_.resourceProvisioningOptions -like '*Team*') { $true }else { $false } } },
107-
@{Name = 'calculatedGroupType'; Expression = {
115+
@{Name = 'groupType'; Expression = {
108116
if ($_.groupTypes -contains 'Unified') { 'Microsoft 365' }
109117
elseif ($_.mailEnabled -and $_.securityEnabled) { 'Mail-Enabled Security' }
110118
elseif (-not $_.mailEnabled -and $_.securityEnabled) { 'Security' }
111119
elseif (([string]::isNullOrEmpty($_.groupTypes)) -and ($_.mailEnabled) -and (-not $_.securityEnabled)) { 'Distribution List' }
112120
}
113121
},
122+
@{Name = 'calculatedGroupType'; Expression = {
123+
if ($_.groupTypes -contains 'Unified') { 'm365' }
124+
elseif ($_.mailEnabled -and $_.securityEnabled) { 'security' }
125+
elseif (-not $_.mailEnabled -and $_.securityEnabled) { 'generic' }
126+
elseif (([string]::isNullOrEmpty($_.groupTypes)) -and ($_.mailEnabled) -and (-not $_.securityEnabled)) { 'distributionList' }
127+
}
128+
},
114129
@{Name = 'dynamicGroupBool'; Expression = { if ($_.groupTypes -contains 'DynamicMembership') { $true } else { $false } } }
115130
$GraphRequest = @($GraphRequest | Sort-Object displayName)
116131
}

Modules/CIPPCore/Public/New-CIPPGroup.ps1

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ function New-CIPPGroup {
4343
try {
4444
# Normalize group type for consistent handling (accept camelCase from templates)
4545
$NormalizedGroupType = switch -Wildcard ($GroupObject.groupType.ToLower()) {
46+
'mail-enabled security' { 'Security'; break }
4647
'*dynamicdistribution*' { 'DynamicDistribution'; break } # Check this first before *dynamic* and *distribution*
4748
'*dynamic*' { 'Dynamic'; break }
4849
'*generic*' { 'Generic'; break }
@@ -57,7 +58,7 @@ function New-CIPPGroup {
5758
}
5859

5960
# Determine if this group type needs an email address
60-
$GroupTypesNeedingEmail = @('M365', 'Distribution', 'DynamicDistribution')
61+
$GroupTypesNeedingEmail = @('M365', 'Distribution', 'DynamicDistribution', 'Security')
6162
$NeedsEmail = $NormalizedGroupType -in $GroupTypesNeedingEmail
6263

6364
# Determine email address only for group types that need it
@@ -95,13 +96,13 @@ function New-CIPPGroup {
9596
Write-LogMessage -API $APIName -tenant $TenantFilter -message "Creating group $($GroupObject.displayName) of type $NormalizedGroupType$(if ($NeedsEmail) { " with email $Email" })" -Sev Info
9697

9798
# Handle Graph API groups (Security, Generic, AzureRole, Dynamic, M365)
98-
if ($NormalizedGroupType -in @('Generic', 'Security', 'AzureRole', 'Dynamic', 'M365')) {
99+
if ($NormalizedGroupType -in @('Generic', 'AzureRole', 'Dynamic', 'M365')) {
99100
Write-Information "Creating group $($GroupObject.displayName) of type $NormalizedGroupType$(if ($NeedsEmail) { " with email $Email" })"
100101
$BodyParams = [PSCustomObject]@{
101102
'displayName' = $GroupObject.displayName
102103
'description' = $GroupObject.description
103104
'mailNickname' = $MailNickname
104-
'mailEnabled' = ($NormalizedGroupType -in @('Security', 'M365'))
105+
'mailEnabled' = ($NormalizedGroupType -eq 'M365')
105106
'securityEnabled' = $true
106107
'isAssignableToRole' = ($NormalizedGroupType -eq 'AzureRole')
107108
}
@@ -194,13 +195,17 @@ function New-CIPPGroup {
194195

195196
$ExoParams = @{
196197
Name = $GroupObject.displayName
197-
Alias = $GroupObject.username
198+
Alias = $MailNickname
198199
Description = $GroupObject.description
199200
PrimarySmtpAddress = $Email
200201
Type = $GroupObject.groupType
201202
RequireSenderAuthenticationEnabled = [bool]!$GroupObject.allowExternal
202203
}
203204

205+
if ($NormalizedGroupType -eq 'Security') {
206+
$ExoParams.Type = 'Security'
207+
}
208+
204209
# Add owners
205210
if ($GroupObject.owners -and $GroupObject.owners.Count -gt 0) {
206211
$OwnerEmails = $GroupObject.owners | ForEach-Object {

0 commit comments

Comments
 (0)