路由表详细信息

时间:2021-07-02 06:35:21

标签: azure powershell azure-devops

是否可以通过路由表名称、订阅、下一跳类型地址前缀从每个订阅中获取路由的所有详细信息。

我试过 'Get-AzRouteTable -ResourceGroupName "" -Name "prod" |获取-AzRouteConfig | Export-Csv azureroutetable2.csv' 但只能从特定环境获取,有没有更好的方法来做同样的事情?

问候

德布拉特

enter image description here

1 个答案:

答案 0 :(得分:0)

根据 Get-AzRouteTable 的帮助,它不需要为 ResourceGroupName 指定任何值,因此我们应该能够遍历您的可用上下文。如果您确实拥有大型 Azure 网络基础结构,并且它们是按资源组逻辑组织的,则您可能还需要考虑循环访问资源组。

话虽如此,你可以做这样的事情。它将为您当前会话中的每个订阅创建一个 csv。如果需要,请更改路径值开头的 . 以设置完整路径。

$Contexts = Get-AzContext -ListAvailable
foreach ($Context in $Contexts) {
    [void](Set-AzContext -SubscriptionId $Context.Subscription.Id)
    $RouteConfig = Get-AzRouteTable -Name "prod" | Get-AzRouteConfig
    # If you are using PowerShell 5.1, add '-NoTypeInformation' to the end of this command.
    $RouteConfig | Export-Csv -Path ".\$($Context.Subscription.Name)_Routes.csv" -Encoding utf8 -NoClobber
}