简体   繁体   中英

Trying to obtain azure webapp status using powershell

I'm encountering an issue when running the get-AzWebApp command in powershell. All I'm trying to do is get a list of the web apps in a particular resource group, then check that they're in a running state.

The command

 $Apps = Get-AzWebApp -ResourceGroupName "<my group name>"

There are only 8 web apps in this RG, but every time I run it, it takes a good minute or so to run, but then fails with the following error ..

The script failed due to call depth overflow. + CategoryInfo : InvalidOperation: (0:Int32) [AppServiceStatusCheck_Test.ps1], RuntimeException + FullyQualifiedErrorId : CallDepthOverflow

Any ideas on how to resolve this would be great.

You can accomplish that using the below snippet but you will need az cli installed.

 az webapp list --resource-group YOURRESOURCEGROUP --query "[?state=='Running']"

Az webapp documentation:
https://docs.microsoft.com/en-us/cli/azure/webapp?view=azure-cli-latest#az-webapp-list

Az installation instructions:
https://docs.microsoft.com/en-us/powershell/azure/install-az-ps?view=azps-8.0.0

If you google the error The script failed due to call depth overflow you get some examples which suggest that either the syntax or the logic within your script is not quite correct or causing an infinite loop of some descritpion.

The error is surfaced from AppServiceStatusCheck_Test.ps1 . Do you have more context in that script that you can provide?

As an alternative to GeralexGR suggestion using PowerShell commands and Search-AzGraph .

# Build a Kusto query as a string
$query = "resources
| where type == 'microsoft.web/sites'
| extend state = properties.state
| project name,state,resourceGroup,location,id,type,kind,subscriptionId
"

# Search-AzGraph requires the Az.ResourceGraph module which is not part of the Az module.
# Install-Module -Name Az.ResourceGraph -Scope CurrentUser
Search-AzGraph -Query $query

If I am just querying Azure I tend to use a Kusto query with Search-AzGraph for speed of complex queries if your dataset is quite large. You can also cheat and find the resources in the portal then click the 'Open Query' to get what you need.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM