因此,我在 Azure 订阅中运行了大约 6 个 VM(4 个 Linux 和 2 个 Windows)。我需要知道虚拟机运行了多长时间。如何使用 PowerShell/CLI/API 实现此目的?
问问题
192 次
1 回答
1
使用Az.billing Powershell 模块中的 Get-UsageAggregates 获取虚拟机在一段时间内的运行时间:
Connect-AzAccount
$vmsUsage = (Get-UsageAggregates -ReportedStartTime "<start time>" -ReportedEndTime "<endtime>" -ShowDetails $true).UsageAggregations | Where-Object {$_.Properties.MeterCategory -eq 'Virtual Machines'}
foreach($usage in $vmsUsage){
echo $usage.Properties
}
于 2020-01-09T05:13:27.850 回答