I needed to make my life easier the other day as a colleague and I worked through setting up a Azure IaaS network topology to connect to an enterprise production network. One of our clients requirements meant that whilst we created the network sites, subnets and segments we needed to report on what we had created to verify it was correct. This simple task of viewing network names and associated subnets is currently missing from the Azure cmdlets, so we have pieced together this quick bit of re-usable code. There isn’t currently a nice way to do a ‘Get-AzureVirtualNetwork’ and instead you only have the portal(s) or a downloadable XML. This isn’t great if you would like to do some validation checks or even a basic CSV dump to report on current configuration to a network administrator.

I’ve only been able to test this on a few VNET configurations but it seems to do the job for me so far. I’m sure that you can add your own trickery to it if you like, but by the time I invest in doing so, Microsoft will have probably released an updated module that includes this functionality. So here it is in all its glory.

The output will give you a nice table that you can export as per below;

[code language=”PowerShell”]
Get-AzureVirtualNetwork | FT
[/code]

Filter to find reference to matching CIDR blocks;

[code language=”PowerShell”]
Get-AzureVirtualNetwork | ? {$_.AddressPrefix -like "10.72.*"} | FT
[/code]

Store the networks and re-use with other Azure cmdlets;

[code language=”PowerShell”]
$APSites = (Get-AzureVirtualNetwork | ? {$_.AddressPrefix -like "10.72.*"})
[/code]

Export the current configuration for a report;

[code language=”PowerShell”]
Get-AzureVirtualNetwork | Export-CSV -Path "c:\Temp\AzureVirtualNetworkConfiguration.csv"
[/code]

If you notice the code snippet I threw in another handy export for all local routes;

[code language=”PowerShell”]
Get-AzureVirtualNetworkRoutes
[/code]

This will be useful to see if you are missing a local route when the list starts getting large.

Category:
Azure Infrastructure, Cloud Infrastructure, PowerShell
Tags:
, , , , ,

Join the conversation! 6 Comments

  1. Excellent work, as always. Suggestion: make sure the attributes always come out in the same order for easier viewing.

  2. Nice work!

    minor bug: When I export it shows as “System.Object[]” for those values which are in a list. I have a list in “AddressPrefix”

  3. Hi, do you have anything similar for ARM.

    • Hi Vishal. The best way to achieve this is using either the Resource Explorer or the new “Automation Script” setting that allows you to create an ARM template from an existing deployment (note that it doesn’t support all Azure capabilities just yet though). Simon.

  4. how can i calculate the available ips in subnet??
    $nic = Get-AzureRmVirtualNetwork -Name TST-VNET1 -ResourceGroupName TST-RG1
    $subnets= $nic.Subnets
    foreach( $subnet in $subnets)
    {
    $subnet.IpConfigurations.Count
    }

    Using this i can get the usable ip is there any way to get available ip in subnet

    • Hi Vivek,
      This is what I use to see if and IP is available to be assigned:
      Test-AzureRMStaticVNETIP -VNETname [name] -IPaddress [the one you want to test] | Select-Object -Property IsAvailable

      Hope that helps!?

Comments are closed.