如何通过PowerShell或Azure门户获取使用特定存储账户的所有Azure资源?
查找Azure中关联特定存储账户的所有资源
PowerShell 方法
Get-AzStorageAccount仅能获取存储账户自身信息,要查询关联资源,推荐使用Azure资源图(高效跨资源/订阅查询),步骤如下:
- 先获取目标存储账户的资源ID:
$storageAccountId = (Get-AzStorageAccount -ResourceGroupName "<resourcegroup>" -Name "<storage acct>").Id
- 执行资源图查询,找出所有引用该存储账户ID的资源:
Search-AzGraph -Query "resources | where properties.storageAccountId == '$storageAccountId' or properties.storageAccount.id == '$storageAccountId' or properties contains '$storageAccountId' | project name, type, resourceGroup"
该查询覆盖了多数资源存储关联信息的字段,返回结果包含资源名称、类型和所属资源组。
如果仅需查询当前订阅内的资源,也可使用以下命令(遍历所有资源,效率较低):
Get-AzResource | Where-Object { $_.Properties -match $storageAccountId } | Select-Object Name, ResourceType, ResourceGroupName
Azure门户方法
方法1:存储账户依赖项视图
- 登录Azure门户,定位到目标存储账户。
- 在左侧菜单的「监视」分类下,打开依赖项页面,这里会展示直接关联的资源(如虚拟机托管磁盘、函数应用、逻辑应用等)。
方法2:Azure资源图 Explorer
- 在门户搜索栏输入「资源图 Explorer」并进入。
- 在查询编辑器中输入Kusto查询语句(替换为你的存储账户资源ID):
resources | where properties contains '<存储账户资源ID>' | project name, type, resourceGroup
- 点击「运行查询」,即可获取所有关联资源的列表。
内容的提问来源于stack exchange,提问作者Christy
相关产品推荐
相关产品推荐

