簡體   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