From 74952d0869c513b4f7b7154c8f9bb76228f0f969 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristian=20Kj=C3=A6rg=C3=A5rd?= Date: Mon, 16 Sep 2024 23:27:24 +0200 Subject: [PATCH] Fix default domain duplication when using alternate method If tenant is deleted it would set the default domain of the deleted tenant, to be the one from the previous one right before it --- Modules/CIPPCore/Public/GraphHelper/Get-Tenants.ps1 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Modules/CIPPCore/Public/GraphHelper/Get-Tenants.ps1 b/Modules/CIPPCore/Public/GraphHelper/Get-Tenants.ps1 index 9d829df360a4..0fdcf0571a64 100644 --- a/Modules/CIPPCore/Public/GraphHelper/Get-Tenants.ps1 +++ b/Modules/CIPPCore/Public/GraphHelper/Get-Tenants.ps1 @@ -111,13 +111,16 @@ function Get-Tenants { } catch { try { #doing alternative method to temporarily get domains. Nightly refresh will fix this as it will be marked for renew. + Write-Host 'Main method failed, trying alternative method.' $Domain = (New-GraphGetRequest -uri "https://graph.microsoft.com/v1.0/tenantRelationships/findTenantInformationByTenantId(tenantId='$($LatestRelationship.customerId)')" -NoAuthCheck:$true).defaultDomainName + Write-Host "Alternative method worked, got domain $Domain." $defaultDomainName = $Domain $initialDomainName = $Domain $RequiresRefresh = $true } catch { - Write-LogMessage -API 'Get-Tenants' -message "Tried adding $($LatestRelationship.customerId) to tenant list but failed to get domains - $($_.Exception.Message)" -level 'Critical' + $ErrorMessage = Get-CippException -Exception $_ + Write-LogMessage -API 'Get-Tenants' -message "Tried adding $($LatestRelationship.customerId) to tenant list but failed to get domains - $($ErrorMessage.NormalizedError)" -Sev 'Critical' -LogData $ErrorMessage } } Write-Host 'finished getting domain'