查询统计ARM模型下VHD实际计费大小

来源:互联网 发布:我想做淘宝怎么弄 编辑:程序博客网 时间:2024/06/08 13:11

查询统计ARM模型下VHD实际计费大小

第一列是路径,LeaseState状态可以看出VHD是否被虚拟机挂载了,可以参考清理无用的VHD

脚本运行截图:


可以看到有两个没在使用的vhd,而第三个vhd是未挂载的空白数据盘vhd

#------------------------------------------------------------------------------    # User own the risk, otherwise exit.# # Azure PowerShell Version:  3.6.0## Create by Zeno. #------------------------------------------------------------------------------  $storages = Get-AzureRmStorageAccount;$TotalCostSizeGB = 0foreach ($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