Home > Mobile >  Trying to obtain azure webapp status using powershell
Trying to obtain azure webapp status using powershell

Time:06-10

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.

CodePudding user response:

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

CodePudding user response:

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.

  • Related