您的位置:首页 > 运维架构 > Shell

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

2017-01-17 17:17 465 查看
此脚本通过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;

       
}

   
}

}

脚本测试结果:




内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ARM Azure Powershell vhd
相关文章推荐