Skip to content

Commit

Permalink
Fix default domain duplication when using alternate method
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kris6673 committed Sep 16, 2024
1 parent 04f03c1 commit 74952d0
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Modules/CIPPCore/Public/GraphHelper/Get-Tenants.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit 74952d0

Please sign in to comment.