Joris Willekens
Joris Willekens

Reputation: 15

KQL script to retrieve information from Azure VM

I'm working on a KQL script to retrieve all kind of information from a Azure VM, what I would like to retrieve is:

Most of them are working fine in below script, however, now I want to add the CPU and memory information to this list. Is there a way that I can extract those 2 out of the vmSize information? Or is there any other way?

resources
| where type == "microsoft.compute/virtualmachines"
| join kind=leftouter (resourcecontainers | where type == "microsoft.resources/subscriptions" | project subscription = name, subscriptionId) on subscriptionId
| extend nicId = tostring(properties.networkProfile.networkInterfaces[0].id)
| join kind=leftouter (resources | where type == 'microsoft.network/networkinterfaces' | project nicId = id, privateIPAllocation = properties.ipConfigurations[0].properties.privateIPAllocationMethod, privateIPAddress = properties.ipConfigurations[0].properties.privateIPAddress) on nicId
| project name, subscription, resourceGroup, location, zones, properties.provisioningState, properties.hardwareProfile.vmSize, properties.extended.instanceView.osName, properties.extended.instanceView.osVersion, properties.extended.instanceView.powerState.displayStatus, properties.licenseType, nicId, privateIPAllocation, privateIPAddress

From all tests that I've performed the CPU and memory information remains empty or returns null

[Result from script] enter image description here

Upvotes: 0

Views: 1727

Answers (1)

Venkat V
Venkat V

Reputation: 7725

KQL script to retrieve information from Azure VM

Here are the steps to retrieve the VM information using KQL Log Query.

  1. Create a Log Analytics Work Space

  2. Go to Monitor in the Azure portal, select Virtual Machines > Not monitored and select your VM > Enable > select your existing Log Analytics Work Space.

enter image description here

  1. After completing the deployment, wait for some time for the data to be sent to Log Analytics Work Space.

  2. Go to Log Analytics Work Space and select Logs. Then run the following KQL query.

VMComputer
| project DisplayName, AzureLocation, AzureResourceGroup, PhysicalMemoryMB,Cpus,Ipv4Addresses

Here is the result

enter image description here

Upvotes: 0

Related Questions