diff --git a/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Settings/Invoke-ExecApiClient.ps1 b/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Settings/Invoke-ExecApiClient.ps1 index dd9fdd54ab66..7e3b75de8e8f 100644 --- a/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Settings/Invoke-ExecApiClient.ps1 +++ b/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Settings/Invoke-ExecApiClient.ps1 @@ -101,7 +101,7 @@ function Invoke-ExecApiClient { 'GetAzureConfiguration' { $Owner = $env:WEBSITE_OWNER_NAME Write-Information "Owner: $Owner" - if ($Owner -match '^(?[^+]+)\+(?[^-]+(?:-[^-]+)*?)(?:-[^-]+webspace(?:-Linux)?)?$') { + if ($env:WEBSITE_SKU -ne 'FlexConsumption' -and $Owner -match '^(?[^+]+)\+(?[^-]+(?:-[^-]+)*?)(?:-[^-]+webspace(?:-Linux)?)?$') { $RGName = $Matches.RGName } else { $RGName = $env:WEBSITE_RESOURCE_GROUP @@ -123,7 +123,7 @@ function Invoke-ExecApiClient { 'SaveToAzure' { $TenantId = $env:TenantID $Owner = $env:WEBSITE_OWNER_NAME - if ($Owner -match '^(?[^+]+)\+(?[^-]+(?:-[^-]+)*?)(?:-[^-]+webspace(?:-Linux)?)?$') { + if ($env:WEBSITE_SKU -ne 'FlexConsumption' -and $Owner -match '^(?[^+]+)\+(?[^-]+(?:-[^-]+)*?)(?:-[^-]+webspace(?:-Linux)?)?$') { $RGName = $Matches.RGName } else { $RGName = $env:WEBSITE_RESOURCE_GROUP diff --git a/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Settings/Invoke-ExecBackendURLs.ps1 b/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Settings/Invoke-ExecBackendURLs.ps1 index 40da6efbdd9c..a9ef82959f51 100644 --- a/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Settings/Invoke-ExecBackendURLs.ps1 +++ b/Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Settings/Invoke-ExecBackendURLs.ps1 @@ -1,4 +1,4 @@ -Function Invoke-ExecBackendURLs { +function Invoke-ExecBackendURLs { <# .FUNCTIONALITY Entrypoint @@ -14,7 +14,7 @@ Function Invoke-ExecBackendURLs { Write-Host 'PowerShell HTTP trigger function processed a request.' $Owner = $env:WEBSITE_OWNER_NAME - if ($Owner -match '^(?[^+]+)\+(?[^-]+(?:-[^-]+)*?)(?:-[^-]+webspace(?:-Linux)?)?$') { + if ($env:WEBSITE_SKU -ne 'FlexConsumption' -and $Owner -match '^(?[^+]+)\+(?[^-]+(?:-[^-]+)*?)(?:-[^-]+webspace(?:-Linux)?)?$') { $RGName = $Matches.RGName } else { $RGName = $env:WEBSITE_RESOURCE_GROUP diff --git a/Modules/CIPPCore/Public/GraphHelper/Get-Tenants.ps1 b/Modules/CIPPCore/Public/GraphHelper/Get-Tenants.ps1 index 88c083dce27f..c3e3847b8b07 100644 --- a/Modules/CIPPCore/Public/GraphHelper/Get-Tenants.ps1 +++ b/Modules/CIPPCore/Public/GraphHelper/Get-Tenants.ps1 @@ -60,7 +60,19 @@ function Get-Tenants { } if ($CleanOld.IsPresent) { - $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 + try { + $GDAPRelationships = New-GraphGetRequest -uri "https://graph.microsoft.com/beta/tenantRelationships/delegatedAdminRelationships?`$filter=status eq 'active'&`$select=customer,autoExtendDuration,endDateTime" -NoAuthCheck:$true + # Filter out MLT relationships locally + $GDAPRelationships = $GDAPRelationships | Where-Object { $_.displayName -notlike 'MLT_*' } + if (!$GDAPRelationships) { + Write-LogMessage -API 'Get-Tenants' -message 'Tried cleaning old tenants but failed to get GDAP relationships - No relationships returned' -Sev 'Critical' + throw 'Failed to get GDAP relationships for cleaning old tenants.' + } + } catch { + $ErrorMessage = Get-CippException -Exception $_ + Write-LogMessage -API 'Get-Tenants' -message "Tried cleaning old tenants but failed to get GDAP relationships - $($_.Exception.Message)" -Sev 'Critical' -LogData $ErrorMessage + throw $_ + } $GDAPList = foreach ($Relationship in $GDAPRelationships) { [PSCustomObject]@{ customerId = $Relationship.customer.tenantId @@ -84,7 +96,13 @@ function Get-Tenants { throw 'RefreshToken not set. Cannot get tenant list.' } #get the full list of tenants - $GDAPRelationships = New-GraphGetRequest -uri "https://graph.microsoft.com/beta/tenantRelationships/delegatedAdminRelationships?`$filter=status eq 'active' and not startsWith(displayName,'MLT_')$RelationshipFilter&`$select=customer,autoExtendDuration,endDateTime&`$top=300" -NoAuthCheck:$true + $GDAPRelationships = New-GraphGetRequest -uri "https://graph.microsoft.com/v1.0/tenantRelationships/delegatedAdminRelationships?`$filter=status eq 'active'$RelationshipFilter&`$select=customer,autoExtendDuration,endDateTime" -NoAuthCheck:$true + # Filter out MLT relationships locally + $GDAPRelationships = $GDAPRelationships | Where-Object { $_.displayName -notlike 'MLT_*' } + Write-Host "GDAP relationships found: $($GDAPRelationships.Count)" + Write-Information "GDAP relationships found: $($GDAPRelationships.Count)" + $totalTenants = $GDAPRelationships.customer.tenantId | Select-Object -Unique + Write-Information "Total tenants found in relationships result: $($totalTenants.count)" $GDAPList = foreach ($Relationship in $GDAPRelationships) { [PSCustomObject]@{ customerId = $Relationship.customer.tenantId diff --git a/version_latest.txt b/version_latest.txt index f6f89a8f8109..0431022f1fa0 100644 --- a/version_latest.txt +++ b/version_latest.txt @@ -1 +1 @@ -8.6.1 +8.6.2 \ No newline at end of file