Partager via


Quick Tip: Listing all IaaS VMs or PaaS Roles on an Azure Virtual Network via PowerShell

When managing Microsoft Azure Virtual Networks via the Azure Management Portal, we can easily see a list of IaaS Virtual Machines and/or PaaS web/worker roles that are connected to a particular virtual network, as shown below.

image
List of resources connected to Azure Virtual Network via Management Portal

Question: How can I determine this same type of list when using PowerShell to manage my Azure subscription?

Answer: Virtual networks are bound to Azure cloud service deployments for IaaS Virtual Machines and PaaS web/worker roles. Use the following PowerShell code snippet to display the list of cloud services, roles and instances that are connected to a particular Azure Virtual Network.

(Get-AzureService |
Get-AzureDeployment |
Where-Object `
-Property VNetName `
-EQ "enter-vnet-name") |
%{
Get-AzureRole `
-ServiceName $_.ServiceName `
-InstanceDetails |
Select-Object `
-Property ServiceName,
InstanceName,
RoleName,
IPAddress
}