-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Open
Labels
App Servicesaka WebSitesaka WebSitesService AttentionThis issue is responsible by Azure service team.This issue is responsible by Azure service team.bugThis issue requires a change to an existing behavior in the product in order to be resolved.This issue requires a change to an existing behavior in the product in order to be resolved.customer-reported
Description
Description
Get-AzWebApp with no further parameters for getting all web apps on a subscription is amazingly slow. Might be related to #18266.
It seems to first get resource groups, then foreach those one by one to look for web apps.
Why not use the API directly to LIST all web apps on a subscription in this case?
Here's an example for getting all web apps much faster:
# Assets
$ResourceType = [string] 'Microsoft.Web/sites'
# Get resources as fast as possibru
## Prepare
$Subscriptions = [PSCustomObject[]](
(Search-AzGraph -UseTenantScope -Query ('resources | where type =~ "{0}" | summarize count() by subscriptionId | project subscriptionId' -f $ResourceType.ToLower())).'Data'
)
$Headers = [ordered]@{
'authorization' = [string] 'Bearer {0}' -f (Get-AzAccessToken -ResourceTypeName 'Arm').'Token'
}
$ApiVersion = [string](
(
Invoke-RestMethod -Method 'Get' -Headers $Headers -Uri (
'https://management.azure.com/subscriptions/{0}/providers/{1}?api-version=2015-01-01' -f $Subscriptions[0].'subscriptionId', $ResourceType.Split('/')[0]
) -SessionVariable 'Session'
).'resourceTypes'.Where(
{$_.'resourceType' -eq ($ResourceType -replace ([string]::Format('^{0}/',$ResourceType.Split('/')[0])),'')},'First'
).'apiVersions'.Where{
-not $_.EndsWith('-preview','InvariantCultureIgnoreCase')
} | Sort-Object -Descending | Select-Object -First 1
)
## Get
$Resources = [PSCustomObject[]](
$Subscriptions.'subscriptionId' | ForEach-Object -ThrottleLimit 10 -Parallel {
[PSCustomObject[]](
$(
Invoke-RestMethod -Uri (
'https://management.azure.com/subscriptions/{0}/providers/{1}?api-version={2}' -f $_, $Using:ResourceType, $Using:ApiVersion
) -Headers $Using:Headers -WebSession $Using:Session
).'value'
)
}
)Issue script & Debug output
Get-AzWebApp # Watch painting dryEnvironment data
PowerShell v7.4.2 x64 on Windows 11 23H2Module versions
Az.Websites v3.2.1Error output
No error.Metadata
Metadata
Assignees
Labels
App Servicesaka WebSitesaka WebSitesService AttentionThis issue is responsible by Azure service team.This issue is responsible by Azure service team.bugThis issue requires a change to an existing behavior in the product in order to be resolved.This issue requires a change to an existing behavior in the product in order to be resolved.customer-reported