脚本运行截图:
可以看到有两个没在使用的vhd,而第三个vhd是未挂载的空白数据盘vhd
#------------------------------------------------------------------------------ # User own the risk, otherwise exit. # # Azure PowerShell Version: 3.6.0 # # Create by Zeno. #------------------------------------------------------------------------------ $storages = Get-AzureRmStorageAccount; $TotalCostSizeGB = 0 foreach ($storage in $storages) { # get storage containers $containers = (Get-AzureStorageContainer -Context $storage.Context).Name foreach ($container in $containers) { #get blobs under all containers $blobs = Get-AzureStorageBlob -Context $storage.Context -Container $container foreach ($blob in $blobs) { # check if blob is PageBlob if ($Blob.Name.EndsWith("vhd")) { $blobSizeInBytes = 0 $blob.ICloudBlob.GetPageRanges() | ForEach-Object { $blobSizeInBytes += $_.EndOffset - $_.StartOffset } $path = $blob.Context.StorageAccountName + "/" + $blob.ICloudBlob.Container.Name + "/" + $blob.Name #+ " " $blob | select @{n="BlobPath_Storage_Container_Blob "; e={$path}},` @{n="DisplaySizeGB"; e={[System.Math]::Truncate($blob.Length /1GB)}},` @{n="CostSizeGB"; e={"{0:f2}" -f ($blobSizeInBytes /1GB)}},` #@{n="BlobType"; e={$blob.BlobType}},` @{n="LeaseState"; e={$blob.ICloudBlob.Properties.LeaseState}} $TotalCostSizeGB += $blobSizeInBytes } } } } Write-Host ("`n`tTotal cost size calculated is {0:F2}GB." -f ($TotalCostSizeGB / 1GB)) -ForegroundColor Green