Forum Discussion
Get Azure Virtual Machine/Virtual Machine Scale Set which are stopped since last 7 days
you can query Azure Resource Graph to find which VMs are currently powered down. There is API/PowerShell/CLI support for Resource Graph.
resources
| where type =~ 'microsoft.compute/virtualmachines' and properties.extended.instanceView.powerState.code has 'deallocated'
Please note that there is not yet VMSS support for power state. For VMSS, you should query the Azure Resource Manager API.
Having the list of deallocated VMs, you could then query Azure Activity Log for the last deallocate action and thus determine for how long your VM was deallocated.
An alternative to this, with a built-in recommendation that gives you VMs that have been deallocated for long, is the Azure Optimization Engine. Please note that you have to let it run at least 2 weeks to get accurate results.
hi.... is it now possible to use the Azure Resource Graph to get the state of a Scale Set ?
you mentioned "Azure Resource Manager API".. how can we do that ?
thx!