Currently trying get a report, preferable a spreadsheet, of all of the VMs in all of my Subscriptions along with their VNets. Similar to how it is presented in portal in the Virtual Machine main page but copying and pasting comes out very sloppy and unstructured.
I explored trying with PowerShell by iterating through all VMs, then pulling the VM name and RG to pull the Nic, then from the Nic get the subnet which contains the Vnet as well. However, I am unsure if this logic is completely sound. The below PS prints the VM name, VM Resource Group, VM Nic name, Nic subnet, and Nic VM. Does this make sense?
$vms = Get-AzureRmVM
Echo "VM Name,VM Resource Group,VM NIC Name,VM Subnet,VM VNet"
foreach ($vm in $vms){
$thisvmName = $vm.Name
$thisvmRG = $vm.ResourceGroupName
$thisvmNicName = $vm.NetworkProfile.NetworkInterfaces.Id.Split("/")[8]
$thisvmNic = Get-AzureRmNetworkInterface -Name $thisvmNicName -ResourceGroupName $thisvmRg
$thisvmNicIPConfig = Get-AzureRmNetworkInterfaceIpConfig -NetworkInterface $thisvmNic
$thisvmNicSubnet = $thisvmNicIpConfig.Subnet.Id.Split("/")[10]
$thisvmNicVNet = $thisvmNicIPConfig.Subnet.Id.Split("/")[8]
echo "$thisvmName,$thisvmRG,$thisvmNicName,$thisvmNicSubnet,$thisvmNicVNet"
}
If there is a completely easier path to getting a spreadsheet of all my VMs in all Subscriptions that I can sort by VNet I am open to it since this is seems pretty excessive. Also, if I can get a count of VMs (not NICS) in VNets that may work for my minimum end goal as well.. Any help would be appreciated!