Skip to content

Commit ae4c826

Browse files
Merge pull request KelvinTegelaar#1538 from kris6673/feat-HiddenFromExchangeClientsEnabled
Feat: Enhance group management functions to support hideFromOutlookClients
2 parents 3028825 + 1c34041 commit ae4c826

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ function Invoke-EditGroup {
1515
$Results = [System.Collections.Generic.List[string]]@()
1616
$UserObj = $Request.Body
1717
$GroupType = $UserObj.groupId.addedFields.groupType ? $UserObj.groupId.addedFields.groupType : $UserObj.groupType
18-
$GroupName = $UserObj.groupName ? $UserObj.groupName : $UserObj.groupId.addedFields.groupName
18+
# groupName is used in the Add to Group user action, displayName is used in the Edit Group page
19+
$GroupName = $UserObj.groupName ?? $UserObj.displayName ?? $UserObj.groupId.addedFields.groupName
1920
$GroupId = $UserObj.groupId.value ?? $UserObj.groupId
2021
$OrgGroup = New-GraphGetRequest -uri "https://graph.microsoft.com/beta/groups/$($GroupId)" -tenantid $UserObj.tenantFilter
2122

@@ -406,6 +407,28 @@ function Invoke-EditGroup {
406407
}
407408
}
408409

410+
# Only process hideFromOutlookClients if it was explicitly sent and is a Microsoft 365 group
411+
if ($null -ne $UserObj.hideFromOutlookClients -and $GroupType -eq 'Microsoft 365') {
412+
try {
413+
$Params = @{ Identity = $GroupId; HiddenFromExchangeClientsEnabled = $UserObj.hideFromOutlookClients }
414+
$null = New-ExoRequest -tenantid $TenantId -cmdlet 'Set-UnifiedGroup' -cmdParams $Params -useSystemMailbox $true
415+
416+
if ($UserObj.hideFromOutlookClients -eq $true) {
417+
$Results.Add("Successfully hidden group mailbox from Outlook for $($GroupName).")
418+
Write-LogMessage -headers $Headers -API $APIName -tenant $TenantId -message "Successfully hidden group mailbox from Outlook for $($GroupName)." -Sev 'Info'
419+
} else {
420+
$Results.Add("Successfully made group mailbox visible in Outlook for $($GroupName).")
421+
Write-LogMessage -headers $Headers -API $APIName -tenant $TenantId -message "Successfully made group mailbox visible in Outlook for $($GroupName)." -Sev 'Info'
422+
}
423+
} catch {
424+
$ErrorMessage = Get-CippException -Exception $_
425+
Write-Warning "Error in hideFromOutlookClients: $($ErrorMessage.NormalizedError) - $($_.InvocationInfo.ScriptLineNumber)"
426+
$action = if ($UserObj.hideFromOutlookClients -eq $true) { 'hide' } else { 'show' }
427+
$Results.Add("Failed to $action group mailbox in Outlook for $($GroupName).")
428+
Write-LogMessage -headers $Headers -API $APIName -tenant $TenantId -message "Failed to $action group mailbox in Outlook for $($GroupName). Error:$($ErrorMessage.NormalizedError)" -Sev 'Error' -LogData $ErrorMessage
429+
}
430+
}
431+
409432
$body = @{'Results' = @($Results) }
410433
# Associate values to output bindings by calling 'Push-OutputBinding'.
411434
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ function Invoke-ListGroups {
6969
# get the outside the organization RequireSenderAuthenticationEnabled setting
7070
$OnlyAllowInternal = New-ExoRequest -tenantid $TenantFilter -cmdlet 'Get-DistributionGroup' -cmdParams @{Identity = $GroupID } -Select 'RequireSenderAuthenticationEnabled' -useSystemMailbox $true | Select-Object -ExpandProperty RequireSenderAuthenticationEnabled
7171
} elseif ($GroupType -eq 'Microsoft 365') {
72-
$UnifiedGroup = New-ExoRequest -tenantid $TenantFilter -cmdlet 'Get-UnifiedGroup' -cmdParams @{Identity = $GroupID } -Select 'RequireSenderAuthenticationEnabled,subscriptionEnabled,AutoSubscribeNewMembers' -useSystemMailbox $true
73-
$OnlyAllowInternal = $UnifiedGroup.RequireSenderAuthenticationEnabled
72+
$UnifiedGroupInfo = New-ExoRequest -tenantid $TenantFilter -cmdlet 'Get-UnifiedGroup' -cmdParams @{Identity = $GroupID } -Select 'RequireSenderAuthenticationEnabled,subscriptionEnabled,AutoSubscribeNewMembers,HiddenFromExchangeClientsEnabled' -useSystemMailbox $true
73+
$OnlyAllowInternal = $UnifiedGroupInfo.RequireSenderAuthenticationEnabled
7474
} else {
7575
$OnlyAllowInternal = $null
7676
}
7777

7878
if ($GroupType -eq 'Microsoft 365') {
79-
if ($UnifiedGroup.subscriptionEnabled -eq $true -and $UnifiedGroup.AutoSubscribeNewMembers -eq $true) { $SendCopies = $true } else { $SendCopies = $false }
79+
if ($UnifiedGroupInfo.subscriptionEnabled -eq $true -and $UnifiedGroupInfo.AutoSubscribeNewMembers -eq $true) { $SendCopies = $true } else { $SendCopies = $false }
8080
} else {
8181
$SendCopies = $null
8282
}
@@ -85,7 +85,7 @@ function Invoke-ListGroups {
8585
if ($BulkRequestArrayList.Count -gt 0) {
8686
$RawGraphRequest = New-GraphBulkRequest -tenantid $TenantFilter -scope 'https://graph.microsoft.com/.default' -Requests @($BulkRequestArrayList) -asapp $true
8787
$GraphRequest = [PSCustomObject]@{
88-
groupInfo = ($RawGraphRequest | Where-Object { $_.id -eq 1 }).body | Select-Object *, @{ Name = 'primDomain'; Expression = { $_.mail -split '@' | Select-Object -Last 1 } },
88+
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 } } },
9090
@{Name = 'calculatedGroupType'; Expression = {
9191
if ($_.mailEnabled -and $_.securityEnabled) { 'Mail-Enabled Security' }
@@ -94,10 +94,11 @@ function Invoke-ListGroups {
9494
if (([string]::isNullOrEmpty($_.groupTypes)) -and ($_.mailEnabled) -and (!$_.securityEnabled)) { 'Distribution List' }
9595
}
9696
}, @{Name = 'dynamicGroupBool'; Expression = { if ($_.groupTypes -contains 'DynamicMembership') { $true } else { $false } } }
97-
members = ($RawGraphRequest | Where-Object { $_.id -eq 2 }).body.value
98-
owners = ($RawGraphRequest | Where-Object { $_.id -eq 3 }).body.value
99-
allowExternal = (!$OnlyAllowInternal)
100-
sendCopies = $SendCopies
97+
members = ($RawGraphRequest | Where-Object { $_.id -eq 2 }).body.value
98+
owners = ($RawGraphRequest | Where-Object { $_.id -eq 3 }).body.value
99+
allowExternal = (!$OnlyAllowInternal)
100+
sendCopies = $SendCopies
101+
hideFromOutlookClients = if ($GroupType -eq 'Microsoft 365') { $UnifiedGroupInfo.HiddenFromExchangeClientsEnabled } else { $null }
101102
}
102103
} else {
103104
$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 } },

0 commit comments

Comments
 (0)