【问题标题】:Get-AzVM data disk total size with Azure powershell cmdlets使用 Azure powershell cmdlet 获取 AzVM 数据磁盘总大小
【发布时间】:2021-01-12 14:11:01
【问题描述】:

我正在使用 Azure Powershell 脚本来提取一些数据。我想获取 VM 的总磁盘数据大小。有人可以帮忙吗?

$virtualM = Get-AzVM -ResourceGroupName $ResourceName
    foreach ($vmachine in $virtualM) {
        #Get VM Name and Total data disk size
        write-host 'VM NAME: '$vmachine.name 'Data disk total size: '$vmachine.StorageProfile.dataDisks.diskSizeGB
        
    }
#current output 
VM NAME: VM1 Datadisk total size: 1023
VM NAME: VM2 Datadisk total size: 1023 1023 1023

#what I am trying to get
VM NAME: VM1 Datadisk total size: 1023
VM NAME: VM2 Datadisk total size: 3069

【问题讨论】:

    标签: azure powershell azure-powershell


    【解决方案1】:

    类似这样的:

    $virtualM = Get-AzVM -ResourceGroupName $ResourceName
        foreach ($vmachine in $virtualM) {
            #Get VM Name and Total data disk size
            $disksum = $vmachine.StorageProfile.dataDisks.diskSizeGB | Measure-Object -Sum | select Sum -ExpandProperty SUM
            write-host 'VM NAME: '$vmachine.name 'Data disk total size: '$disksum
            
        }
    

    VM NAME:1111 数据盘总大小:100
    VM NAME:2222 数据盘总大小:2048
    VM NAME:3333 数据盘总大小:7576
    VM NAME:4444 数据盘总大小:7376
    VM NAME:5555 数据盘总大小:7320

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-04-11
      • 2022-08-20
      • 1970-01-01
      • 2017-12-06
      • 1970-01-01
      • 1970-01-01
      • 2010-10-07
      相关资源
      最近更新 更多