使用 Azure powershell cmdlet 获取 AzVM 数据磁盘总大小

Get-AzVM data disk total size with Azure powershell cmdlets

我正在使用 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

像这样:

$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 Data disk total size: 100
VM NAME: 2222 Data disk total size: 2048
VM NAME: 3333 Data disk total size: 7576
VM NAME: 4444 Data disk total size: 7376
VM NAME: 5555 Data disk total size: 7320