Skip to content

Commit 4c7ac33

Browse files
authored
Merge pull request #519 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents 184a8f0 + 9fb0f85 commit 4c7ac33

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

Modules/CIPPCore/Public/GraphHelper/Get-Tenants.ps1

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,17 @@ function Get-Tenants {
6060
}
6161

6262
if ($CleanOld.IsPresent) {
63-
$GDAPRelationships = New-GraphGetRequest -uri "https://graph.microsoft.com/beta/tenantRelationships/delegatedAdminRelationships?`$filter=status eq 'active' and not startsWith(displayName,'MLT_')&`$select=customer,autoExtendDuration,endDateTime&`$top=300" -NoAuthCheck:$true
63+
try {
64+
$GDAPRelationships = New-GraphGetRequest -uri "https://graph.microsoft.com/beta/tenantRelationships/delegatedAdminRelationships?`$filter=status eq 'active' and not startsWith(displayName,'MLT_')&`$select=customer,autoExtendDuration,endDateTime&`$top=300" -NoAuthCheck:$true
65+
if (!$GDAPRelationships) {
66+
Write-LogMessage -API 'Get-Tenants' -message 'Tried cleaning old tenants but failed to get GDAP relationships - No relationships returned' -Sev 'Critical'
67+
throw 'Failed to get GDAP relationships for cleaning old tenants.'
68+
}
69+
} catch {
70+
$ErrorMessage = Get-CippException -Exception $_
71+
Write-LogMessage -API 'Get-Tenants' -message "Tried cleaning old tenants but failed to get GDAP relationships - $($_.Exception.Message)" -Sev 'Critical' -LogData $ErrorMessage
72+
throw $_
73+
}
6474
$GDAPList = foreach ($Relationship in $GDAPRelationships) {
6575
[PSCustomObject]@{
6676
customerId = $Relationship.customer.tenantId

0 commit comments

Comments
 (0)