[Azure]ARM模式下使用Powershell找出订阅中没有被使用的vhd

来源:互联网 发布:2017大数据概念股龙头 编辑:程序博客网 时间:2024/05/18 03:51

此脚本通过Powershell来找到ARM订阅中没有被使用的VHD,脚本如下:

$storages= Get-AzureRmStorageAccount;

foreach ($storagein $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;

       }

   }

}

脚本测试结果:


87 0
原创粉丝点击