如何使用Powershell从订阅计算所有Azure存储表的大小

时间:2019-10-31 22:49:55

标签: powershell azure-storage azure-table-storage azure-powershell azure-tablequery

如何使用Powershell从订阅中计算所有Azure存储表的大小。

我尝试在线搜索是否有任何直接的查询表大小的方法,但看起来没有。 有人可以给我一个计算Azure存储表大小的工作模型吗?

请。

List<Customer> customers = Enumerable.Range(0, 10).Select(c =>
    new Customer
    {
        Name = "Pedro",
        Age = "20",
        Products = Enumerable.Range(0, 3).Select(p => new Product
        {
            Code = "1",
            Price = "400.00"
        }).ToArray()
    }).ToList();

1 个答案:

答案 0 :(得分:0)

您可以计算所有Azure存储表的大小,但是最小粒度可以只是存储帐户中的所有表,而不是特定的表。

尝试以下命令,对我来说效果很好。

$StorageAccounts = Get-AzStorageAccount
foreach($item in $StorageAccounts){
    $id = $item.Id+"/tableServices/default"
    $name = $item.StorageAccountName
    $metric = Get-AzMetric -ResourceId $id -MetricName "TableCapacity" -WarningAction Ignore
    $data = $metric.Data.Average/1024/1024
    Write-Output "Tables in $name : $data MB"
}

enter image description here


此外,看起来您想在多个订阅中使用该命令,如果是这样,我认为您需要先运行Set-AzContext来设置订阅,然后再运行上述命令。

Set-AzContext -SubscriptionId "xxxx-xxxx-xxxx-xxxx"