View all VMs in an Azure Virtual Network

View all VMs in an Azure Virtual Network

Q. How can I view all VMs in Azure that are in a Virtual Network?

A. I recommend always placing Azure VMs in an explicitly created virtual network which gives full control of the IP address space used and DNS configuration. To check what VMs are in a virtual network use the following PowerShell.

Get-AzureVM | where-object { $_.VirtualNetworkName -notlike "" } | select DeploymentName,HostName,VirtualNetworkName 

This will display information about all the VMs that are in a virtual network. You can also show VMs not in a virtual network using:

Get-AzureVM | where-object { $_.VirtualNetworkName -like "" } | select DeploymentName,HostName,VirtualNetworkName 

If you want to see the VMs in a specific virtual network add the network name in the PowerShell. For example:

Get-AzureVM | where-object { $_.VirtualNetworkName -like "VirtNet115" } | select DeploymentName,HostName,VirtualNetworkName

Note that you need to be running PowerShell 8.16 (run (Get-Module Azure).Version to check) or above for this to work as this enables access to the VirtualNetworkName property.

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish