Check number of used VHDs in ARM storage account?
A simple script to check the number of VHDs in use in a single ARM storage account.
June 22, 2016
Q. How can I check the number of VHDs in an ARM storage account?
A. Each Azure IaaS VM attached disk for a standard tier VM in a standard storage account provides up to 500 IOPS and each storage account provides up 20,000 IOPS. This means you should never have more than 40 used VHD files in a storage account. You can have additional VHD files that are not currently used by VMs, you care about VHDs attached to VMs which can be detected by a lease on the page blob containing the VHD. With ARM there is no concept of a disk as its own entity with its own lifecycle. Instead a disk is a page blob that is attached to a VM. The code below will highlight if you have more than 40 VHDs used by VMs in a storage account. Change the storage account name and resource group at the start of the code.
$AzStorAccName = 'savtechsalrsscus' #Storage account name$AzResGroup = 'rg-scusa' #resource group name$VHDsinAct = 0$AllBlobs = Get-AzureRMStorageAccount -Name $AzStorAccName -ResourceGroupName $AzResGroup | Get-AzureStorageContainer | where {$_.Name -eq 'vhds'} | Get-AzureStorageBlob | where {$_.Name.EndsWith('.vhd')} foreach ($Blob in $AllBlobs){ if($Blob.ICloudBlob.Properties.LeaseState -eq 'Leased' -and $Blob.ICloudBlob.Properties.LeaseDuration -eq 'Infinite') { #Assume its used by a VM $outString = "VHD " + $Blob.Name + " used by VM" Write-Output $outString $VHDsinAct++ }}if($VHDsinAct -le 40){ Write-Output "Total of $VHDsinAct VHDs in storage account"}else #more than 40{ Write-Output "*** More than 40 VHDs ($VHDsinAct) in storage account ***"}
About the Author
You May Also Like