此腳本通過Powershell來找到ARM訂閱中沒有被使用的VHD,腳本如下:
$storages = Get-AzureRmStorageAccount;
foreach ($storage in $storages)
{
# get storage context
$context = $storage.Context;
#get page blobs under container vhds (vhds are pageblobs)
$blobs = Get-AzureStorageBlob -Context$context -Container"vhds" -ErrorActionIgnore |where {$_.BlobType -eq"PageBlob"};
foreach ($blobin $blobs)
{
# check if VHD is not in use
if ($blob.Name.EndsWith(".vhd") -and$blob.ICloudBlob.Properties.LeaseState-eq "Available"-and $blob.ICloudBlob.Properties.LeaseStatus -eq"Unlocked")
{
# out put unused vhd information
Write-Host "StorageAccount Name : " $storage.StorageAccountName;
Write-Host "ContainerName : vhds"
Write-Host "BlobName : " $blob.Name;
}
}
}
腳本測試結果:
