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...
goblehp
Nov 25, 2021Copper Contributor
This seems simpler to me because I don't know how to program like you guys do. Maybe it will help a sysadmin like myself.
$SourceVmObject = Get-AzVM -name 'HPG-DA-2'
$SourceVMNIC = $SourceVmObject.NetworkProfile.NetworkInterfaces[0].Id | Get-AzNetworkInterface
$SourceSubscriptionVnets = Get-AzVirtualNetwork
$SourceSubscriptionVnet = $SourceSubscriptionVnets | where {$_.subnets.ipconfigurations.id -eq $SourceVMNIC.IpConfigurations.id}
$SourceSubscriptionVnet.Name