Forum Discussion
jalilmed
Dec 28, 2022MCT
How to Get Last Reboot VM using Azure Graph Query
Hello, I want to create an Azure Dashboard using Graph Query with date of the last reboot or power-Off. Thanks for help
Clive_Watson
Dec 29, 2022Bronze Contributor
jalilmed This may help get you started (it will need work). The challenge with the graph is getting the time of the last action
resources
| where type has 'microsoft.compute/virtualmachines/extensions' or type has 'microsoft.hybridcompute/machines/extensions'
| where name has 'MicrosoftMonitoringAgent' or name has 'OmsAgentForLinux' or name has 'AzureMonitorWindowsAgent' or name has 'AzureMonitorLinuxAgent'
| extend AzureVM = extract('virtualMachines/(.*)/extensions',1,id), ArcVM = extract('machines/(.*)/extensions',1,id)
| summarize count() by name=tolower(AzureVM), ArcVM=tolower(ArcVM), subscriptionId, resourceGroup, AgentType=name
| extend hasBoth = iff(count_ > 1, 'Yes', 'No')
| join
(
resources
| where type =~ 'Microsoft.Compute/virtualMachines'
| project name, properties.extended.instanceView.powerState.displayStatus,
properties.extended.instanceView.powerState.code,
created_ = properties.timeCreated
| order by name desc
) on name
jalilmed
Dec 29, 2022MCT
Clive_Watson I will test this and get back to you. Thank you for your message