Export or Backup Azure Route Table into CSV using PowerShell
There could be many use cases where you may want to export Azure route tables into CSV. Here is the PowerShell script that you can use to export Azure Route Tables into CSV using PowerShell script. This script will export Azure Route Tables along with routes of all Active subscriptions into a CSV.
$outputfinal=@()foreach ( $Subscription in $(Get-AzSubscription| Where-Object {$_.State -ne "Disabled"}) ){Select-AzSubscription -SubscriptionId $Subscription.SubscriptionId$rts=Get-AzureRmroutetableforeach ($rt in $rts){$routes=$rt.routesforeach ($route in $routes){$Outputtemp = “” | SELECT RTName,RGName,Location,RouteName,AddressPrefix,NextHopType,NextHopIPAddress$outputtemp.RTName=$rt.name$outputtemp.RGName=$rt.Resourcegroupname$outputtemp.location=$rt.location$outputtemp.routename=$route.Name$outputtemp.AddressPrefix=$route.AddressPrefix$outputtemp.nexthoptype=$route.nexthoptype$outputtemp.NextHopIPAddress=$route.NextHopIPAddress$outputfinal += $outputtemp } }$outputfinal |export-csv ./clouddrive/.cloudconsole/RouteTables_"$((Get-Date).ToString("yyyyMMdd_HHmmss")).csv" -NoTypeInformation
Following is the sample output of this script
If you want to export the CSV to Azure Storage file share, you can remove the last line from above script and add following lines.
$outputfinal | Export-Csv "$Env:temp/RouteTables" -NoTypeInformation$resourceGroupName="myresourcegroup"$storageAccName="mystorageaccount"$fileShareName="myfileshare"$fileName="$Env:temp/RouteTables"$folderPath="/"Function UploadFiles{ Set-AzContext -SubscriptionId 2gdj2342-gl39-390r-h208-84957dg897g8$ctx=(Get-AzStorageAccount -ResourceGroupName $resourceGroupName -Name $storageAccName).ContextSet-AzStorageFileContent -ShareName $fileShareName -context $ctx -Source $fileName -Path $folderPath/"RouteTables_$((Get-Date).ToString("yyyyMMdd_HHmmss")).csv"}UploadFiles
If you are looking for a script that can export Azure Route Tables the similar way, you can check out the script at Export or Backup Network Security Groups into CSV using PowerShell
Comments
Post a Comment