Export or Backup Azure Virtual Networks or Subnet information into CSV using PowerShell

 There may be times when you  want to get a report that contains information of all VNETS along with their subnets and address prefixes. You might have question, how to export or backup Azure VNET or subnets information into CSV.  This script will export Azure Virtual Network information along with subnets and address prefixes of all Active subscriptions into a CSV.


$outputfinal=@()
foreach ( $Subscription in $(Get-AzSubscription| Where-Object {$_.State -ne "Disabled"}) )
{
Select-AzSubscription -SubscriptionId $Subscription.SubscriptionId
$nets=Get-AzVirtualNetwork
foreach ($net in $nets)
{
$snets=$net.Subnets
foreach ($snet in $snets)
{
$outputtemp = "" | SELECT  VNET,VNET_AddressSpace,VNET_Location,ResourceGroup,Subnet_Name,Subnet_AddressPrefix
$outputtemp.VNET=$net.Name
$outputtemp.VNET_AddressSpace=$net.AddressSpace.AddressPrefixes.trim('{}')
$outputtemp.VNET_Location=$net.Location
$outputtemp.ResourceGroup=$net.ResourceGroupName
$outputtemp.Subnet_Name=$snet.Name
$outputtemp.Subnet_AddressPrefix=$snet.AddressPrefix.trim('{}')
$outputfinal += $outputtemp
}
}
}
#$outputfinal | Format-Table
$outputfinal | Export-Csv ./clouddrive/.cloudconsole/NETS_"$((Get-Date).ToString("yyyyMMdd_HHmmss")).csv" -NoTypeInformation




 

Comments

Post a Comment

Popular posts from this blog

Anyconnect SSL-Client VPN with Self-signed Certificate on Cisco ASA

Filtering Routes in BGP using Route-maps and Prefix-list

Open Shortest Path First (OSPF)

IKEv2 IPsec Site-to-Site VPN configuration on Cisco ASA 8.4(x)

IPsec VPN as a Backup for Point-to-Point Link using IP SLA

Border Gateway Protocol (BGP)

Cisco ASA Active/Active Failover Configuration

Bypassing Proxy Server in Google Chrome

Cisco ASA Active/Standby Failover Configuration