有没有办法使用 PowerShell 脚本访问 Azure 路由表的路由?



例如,假设我有一个名为"MyRouteTable"的路由表,并且此路由表有十个路由。我想为这些路由中的每一个分配一个新的 NextHopAddress。

有没有办法使用 PowerShell 脚本以编程方式获取这些路由,以便我可以循环访问它们?

您可以使用以下命令获取所有路由名称:

$table = Get-AzureRmRouteTable -ResourceGroupName "TestGP" -Name "routetable"
# All the routes name will be stored in $routes
$routes = @()
foreach ($routeName in $table.Routes)
{
    $routes += $i.Name
}
# Custom code here

然后,您可以循环路由名称并更新路由,如下所示:

foreach ($routeName in $routes)
{
    Set-AzureRmRouteConfig -Name $routeName -RouteTable $table -AddressPrefix <address prefix> -NextHopType <type>
}
# Sets the goal state for route table
Set-AzureRmRouteTable -RouteTable $table

最新更新