Export Azure Vnet Confguration Settings to a CSV file

DeHaven Graham 101 Reputation points
2021-06-17T18:31:17.987+00:00

Hi,

Does anyone know how I can modify my pre-exisiting script to export all settings into a csv for my vnet configuration?

$vnets =Get-AzVirtualNetwork|
Select-Object SubscriptionName,ResourceGroupName,Name, @{
label='AddressSpace'
expression={$.AddressSpace.AddressPrefix}}, @{
label='SubnetName'
expression={$
.Subnets.Name}
}, @{
label='SubnetAddressSpace'
expression={$_.Subnets.AddressPrefix}
}

$vnets | convertto-csv

107301-image.png

Azure Virtual Network
Azure Virtual Network
An Azure networking service that is used to provision private networks and optionally to connect to on-premises datacenters.
2,138 questions
0 comments No comments
{count} votes

Accepted answer
  1. Andreas Baumgarten 96,281 Reputation points MVP
    2021-06-19T22:51:55.263+00:00

    Hi @DeHaven Graham ,

    I am not sure what's your definition of "all settings" but maybe this is helpful to go further with your script:

    $a = "------------------------------------------------------------------------------------------------------------------"              
    $vnetObjs = Get-AzVirtualNetwork   
    foreach ($vnetobj in $vnetObjs) {  
        $resultvNet = "vNet Name: " + $vnetObj.Name  
        $resultvNet  
        $resultPeering = "Peering: " + (Get-AzVirtualNetworkPeering -Name "*" -VirtualNetwork $vnetObj.Name -ResourceGroupName $vnetobj.ResourceGroupName | Select-Object -ExpandProperty Name)  
        $resultPeering  
        if ($vnetobj.DhcpOptions.DnsServers){  
            $resultDNS = "DNS Server: " + $vnetobj.DhcpOptions.DnsServers  
            }  
        else {  
            $resultDNS = "DNS Server: Azure Default"   
            }  
        $resultDNS  
        $resultIPAddress = $vnetobj | Get-AzVirtualNetworkSubnetConfig | Select-Object Name,AddressPrefix  
        $resultIPAddress  
        $a   
        }      
    

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten


0 additional answers

Sort by: Most helpful