Dec 23 2019 11:32 AM
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.
Thanks,
Nathan
Dec 26 2019 03:35 AM
Solution@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
$vm.VMAgent.VmAgentVersion
However, the VM must be running to get all the details.
Feb 23 2022 12:24 PM
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
Feb 23 2022 02:09 PM
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.
Oct 24 2022 05:18 AM
@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}