如何在PowerShell中获取Azure容器的大小

Tec*_*bic 2 azure azure-storage-blobs azure-powershell

与此问题类似如何获取Azure CloudBlobContainer的大小

如何在PowerShell中获取Azure容器的大小.我可以在https://gallery.technet.microsoft.com/scriptcenter/Get-Billable-Size-of-32175802上看到建议的脚本,但想知道在PowerShell中是否有更简单的方法

小智 5

使用Azure PowerShell,您可以Get-AzureStorageBlob使用Container和Context参数列出容器中的所有blob,例如:

$ctx = New-AzureStorageContext -StorageAccountName youraccountname -storageAccountKey youraccountkey

$blobs = Get-AzureStorageBlob -Container containername -Context $ctx
Run Code Online (Sandbox Code Playgroud)

输出Get-AzureStorageBlob是一个数组AzureStorageBlob,其中包含一个带有名称的属性ICloudBlob,您可以在其中获取blob长度 Properties,然后您可以将所有blob的长度相加以获得容器的内容长度.

  • 一点警告:如果blob容器太大,最终会使用此代码获得OutOfMemoryException.您可以通过实现MaxCount和ContinuationToken来批量检索blob来解决此问题 (3认同)