Open
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 dry
Environment data
PowerShell v7.4.2 x64 on Windows 11 23H2
Module versions
Az.Websites v3.2.1
Error output
No error.