Using Azure Resource Graph explorer, you will get:
resources
| project properties,
type
| where type == "microsoft.compute/virtualmachines"
Output:
instanceView": {
"hyperVGeneration": "V1",
"computerName": "ceuubfcv",
"powerState": {
"displayStatus": "VM running",
"code": "PowerState/running",
"level": "Info"
},
"osVersion": "18.04",
"osName": "ubuntu"
}
},
"vmId": "76vvgtchiufd4e"
}

Alternatively, you can use below PowerShell command to get vm version agent and I followed Microsoft-Document and @Rakhesh sasidharan's Blog:
$vio = (Invoke-AzRestMethod -Path ('/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Compute/virtualMachines/{2}/instanceView?api-version=2021-11-01' -f "XX","YY","ZZ") -Method 'GET' | Select-Object -ExpandProperty Content | ConvertFrom-Json)
$vio
$vio.vmAgent
XX-Subscription ID
YY-Resourcegroup
ZZ- Name Of VM

Using KQL, I found below query you can get agent id and some details of vm:
VMComputer
So you can use Rest api , resource graph and powershell to get details of Vm. Using KQL all the details are not retrieved AFAIK.