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

问题描述 投票:0回答:1

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

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

请。

FOREACH ($SubscriptionID in $Subscriptions) { 
    Write-Host -ForegroundColor Green "Working on $N. $SubscriptionID" 

    $StorageAccounts = Get-AzStorageAccount
    FOREACH ($StorageAccount in $StorageAccounts) {
            $StorageAccountName = $StorageAccount.StorageAccountName
            Write-Host -ForegroundColor Yellow "Working on $StorageAccountName"

            $AllTables = Get-AzStorageTable -Context $StorageAccount.Context
            FOREACH ($TableName in $AllTables) {
                
                $Name = $TableName.Name
                Write-Host -ForegroundColor Green "Working on $StorageAccountName,$Name"
                Get-AzStorageTable –Name $TableName.Name –Context $StorageAccount.Context
                
                }             
            }
            $N = $N+1
    }
powershell azure-storage azure-table-storage azure-powershell azure-tablequery
1个回答
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


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

Set-AzContext
© www.soinside.com 2019 - 2024. All rights reserved.