I want to write a script (preferably PowerShell calling the Az cli modules) that lists of all Windows VMs (whether allocated or de-allocated), subscription, resource-group, vm-name, the os system, the OS version, latest patch information under all Azure subscriptions under a single Azure Tenant. Want this in table format.
There are a number of scripts on the internet but use the 'old' Az modules.
I need help in identifying the Az modules to use and fields to query.
My high level pseudo logic.
$tenant_id = xxxx-xxxx-xxxx-xxxx
$subscription_array = Get-All-Subcriptions -tenant $tenant_id
for(each $sub in $subscription_array)
{
$vm_array = Get-Windows-Vms -subscription $sub
for(each $vm in $vm_array)
{
$vm_name = $vm.name
$vm_os = $vm.os -- Windows-2019, Windows_server-2012 etc...
$vm_rg = $vm.resource_group
$vm_patch_version = $vm.latest_patch_no
$collection_of_vm_records.add($vm_name, $vm_os, $vm_rg, $vm_patch_version)
}
}
Write $collection_of_vm_records to csv file