Forum Discussion
Christian Forjahn
Mar 25, 2017Brass Contributor
PowerShell: Find VNet of an ARM VM
Hi everyone,
it took me quite some time to find a way to get the VNet an ARM VM belongs to by using PowerShell. I don't think this is the perfect solution, but I would like to share it in order...
Jakob Gottlieb Svendsen
Mar 29, 2017Copper Contributor
Hello!
Funny, that it isnt straight forward to get the vNet!
I tried to do it using another method, but in the end I am not sure it is better than yours. :)
$RG = "HybridWorkers"
$VMName = "AA10"
Login-AzureRmAccount
$VM = Get-AzureRMVM -ResourceGroupName $RG -Name $VMName
$VMNicName = $vm.NetworkProfile.NetworkInterfaces.Id.Split("/")[-1]
$VMNic = Get-AzureRmNetworkInterface -ResourceGroupName $RG -Name
$VMvNetName = $VMNic.IpConfigurations.Subnet.Id.Split("/")[8]
$vNet = Get-AzureRmVirtualNetwork -ResourceGroupName $RG -Name $VMvNetName
$vNetIt think it is quite weird that the command outputs this "Id" but afaik the other commands cannot use that as input to get a resource. :)