繁体   English   中英

尝试使用 powershell 获取 azure webapp 状态

[英]Trying to obtain azure webapp status using powershell

在 powershell 中运行 get-AzWebApp 命令时遇到问题。 我要做的就是获取特定资源组中的 Web 应用程序列表,然后检查它们是否处于运行状态。

命令

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

此 RG 中只有 8 个 Web 应用程序,但每次我运行它时,都需要花费一分钟左右的时间才能运行,但随后失败并出现以下错误..

由于调用深度溢出,脚本失败。 + CategoryInfo : InvalidOperation: (0:Int32) [AppServiceStatusCheck_Test.ps1], RuntimeException + FullyQualifiedErrorId : CallDepthOverflow

关于如何解决这个问题的任何想法都会很棒。

您可以使用以下代码段完成此操作,但您需要安装az cli

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

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

az 安装说明:
https://docs.microsoft.com/en-us/powershell/azure/install-az-ps?view=azps-8.0.0

如果你用谷歌搜索错误The script failed due to call depth overflow ,你会得到一些例子,这些例子表明你的脚本中的语法或逻辑不太正确,或者导致某些描述的无限循环。

该错误来自AppServiceStatusCheck_Test.ps1 您可以在该脚本中提供更多上下文吗?

作为使用 PowerShell 命令和Search-AzGraph的 GeralexGR 建议的替代方案。

# 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

如果我只是查询 Azure,如果您的数据集非常大,我倾向于使用带有Search-AzGraph的 Kusto 查询来提高复杂查询的速度。 您也可以作弊并在门户中找到资源,然后单击“打开查询”以获取所需的资源。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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