- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to retrieve the Azure VM vNet name using PowerShell?
To retrieve the Azure Virtual Network (vNet) or subnet name, we need the first name of the network interface of the VM. Below is the command to retrieve the name of the network interface.
$vm = Get-AzVM -VMName Testmachine2k16
TestMachine2k16 is the Azure VM name. Assuming this VM has a single NIC attached.
PS C:\> $nic = $vm.NetworkProfile.NetworkInterfaces PS C:\> $networkinterface = ($nic.id -split '/')[-1] PS C:\> $networkinterface testmachine2k16619
So our NIC name is stored inside the $NetworkInterface variable.
If you have the multiple NICs attached, then use the below command to retrieve the NIC details.
$nics = $vm.NetworkProfile.NetworkInterfaces foreach($nic in $nics) { ($nic.Id -split '/')[-1] }
Once we have the nic details we can retrieve the NIC details using the Get-AzNetworkInterface command.
PS C:\> $nicdetails = Get-AzNetworkInterface -Name $networkinterface
vNet name is stored inside the IPConfigurations and Subnet property.
PS C:\> $nicdetails.IpConfigurations.Subnet
We need to retrieve the Subnet from the ID property. Use the below command to retrieve the same.
PS C:\> ($nicdetails.IpConfigurations.subnet.Id -split '/')[-3]
You will get the name of the vNet. For multiple NICs, repeat this process.
- Related Articles
- How to retrieve the Azure VM Subscription Name using PowerShell?
- How to retrieve the Azure VM NIC name using PowerShell?
- How to retrieve the Azure VM nic name using Azure CLI in PowerShell?
- How to retrieve the Azure VM resource group using PowerShell?
- How to retrieve the Azure VM deallocated date using PowerShell?
- How to retrieve the OS of the Azure VM using Azure CLI in PowerShell?
- How to retrieve the Operating system of the Azure VM using PowerShell?
- How to retrieve the Azure VM RAM and CPU size using PowerShell?
- How to retrieve the Azure VM network security group (NSG) using PowerShell?
- How to retrieve the OS caching setting of Azure VM using Azure\nCLI in PowerShell?
- How to get the Azure VM DNS name using PowerShell?
- How to deallocate the Azure VM using Azure CLI in PowerShell?
- How to start the Azure VM using Azure CLI in PowerShell?
- How to stop the Azure VM using Azure CLI in PowerShell?
- How to restart the Azure VM using Azure CLI in PowerShell?
