VM Agent Status and Version Reporting

Occasional Contributor

Hello, I'm trying to see if there is anyway to pull information that is listed in the portal via PS/CLI/API/Graph across subscriptions.


I'm specifically looking for the current "Agent Status" and version seen here:




From what I can find the information in the OSProfile property does not always exist depending on how the VM was deployed and even when it does, it only lists True, not the status or the version.






5 Replies
best response confirmed by nathan_mitten_rpa (Occasional Contributor)

@nathan_mitten_rpa, when you query for an individual VM with the "Status" switch, you get the VM Agent details, as follows:


$vm = Get-AzVm -Name "vm name" -ResourceGroupName "RG name" -Status



However, the VM must be running to get all the details.

Hi @hspinto 


IS there a way to do this based at the RG level so I can get the agent version from all my vms that are on that RG



I believe there's a more efficient way of doing it, but this should work:


$vmStatuses = @(); Get-AzVM -ResourceGroupName myResourceGroupName | ForEach-Object { $vmStatus = Get-AzVM -Status -ResourceGroupName $_.ResourceGroupName -Name $_.Name; $vmStatuses += $vmStatus }


The $vmStatuses array will contain all the details for each VM, including the agent version, for the VMs that are running.

Thanks alot it worked!

@hspintonever use += operator when working with collections, it's an anti-pattern.

In this case you can use just

$vmStatuses = Get-AzVM -ResourceGroupName myResourceGroupName | ForEach-Object { Get-AzVM -Status -ResourceGroupName $_.ResourceGroupName -Name $_.Name}