diff --git a/Modules/CIPPCore/Public/Entrypoints/Invoke-ListContacts.ps1 b/Modules/CIPPCore/Public/Entrypoints/Invoke-ListContacts.ps1 index 8404992961fee..6fb5562635a41 100644 --- a/Modules/CIPPCore/Public/Entrypoints/Invoke-ListContacts.ps1 +++ b/Modules/CIPPCore/Public/Entrypoints/Invoke-ListContacts.ps1 @@ -30,9 +30,6 @@ Function Invoke-ListContacts { $TenantFilter = $Request.Query.tenantFilter $ContactID = $Request.Query.id - # Write-Host "Tenant Filter: $TenantFilter" - # Write-Host "Contact ID: $ContactID" - # Validate required parameters if (-not $TenantFilter) { $StatusCode = [HttpStatusCode]::BadRequest @@ -47,18 +44,18 @@ Function Invoke-ListContacts { "https://graph.microsoft.com/beta/contacts?`$top=999&`$select=$($selectList -join ',')" } - # Write-Host "Making Graph API request to: $graphUri" - # Make the Graph API request $GraphRequest = New-GraphGetRequest -uri $graphUri -tenantid $TenantFilter + if ([string]::IsNullOrWhiteSpace($ContactID) -eq $false) { + $HiddenFromGAL = New-EXORequest -tenantid $TenantFilter -cmdlet 'Get-Recipient' -cmdParams @{RecipientTypeDetails = 'MailContact' } -Select 'HiddenFromAddressListsEnabled,ExternalDirectoryObjectId' | Where-Object { $_.ExternalDirectoryObjectId -eq $ContactID } + $GraphRequest | Add-Member -NotePropertyName 'hidefromGAL' -NotePropertyValue $HiddenFromGAL.HiddenFromAddressListsEnabled + } # Ensure single result when ID is provided if ($ContactID -and $GraphRequest -is [array]) { $GraphRequest = $GraphRequest | Select-Object -First 1 } - $StatusCode = [HttpStatusCode]::OK - # Write-Host (ConvertTo-Json $GraphRequest -Depth 5) } catch { $ErrorMessage = Get-NormalizedError -Message $_.Exception.Message $StatusCode = [HttpStatusCode]::InternalServerError