So, I have about six VMs (4 Linux & 2 Windows) running in an Azure subscription. I need to know how long the VMs have been running. How do I achieve this using a PowerShell/CLI/API?
Use Get-UsageAggregates in Az.billing Powershell module to get the running time of your VMs in a period of time:
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
}