Azure / Azure/azure-powershell

`Get-AzWebApp` on subscription is very slow

Open
#24,983 3 comments 0 reactions 0 assignees View on GitHub
act-observability-squad App Services bug customer-reported Service Attention
Dominant language
C#
Stars
4.8k
Forks
4.3k
Avg merge
2d 17h
Merged PRs (30d)
51

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:

```powershell
# 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

```PowerShell
Get-AzWebApp # Watch painting dry
```

### Environment data

```PowerShell
PowerShell v7.4.2 x64 on Windows 11 23H2
```

### Module versions

```PowerShell
Az.Websites v3.2.1
```

### Error output

```PowerShell
No error.
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.