Update-NvaIpinRouteTable.psm1
<#
.Synopsis Get the selected route table, and changes the NextHopIpAddress for the Routes with NextHopType selected as VirtualAppliance. .Description Get the selected route table, and changes the NextHopIpAddress for the Routes with NextHopType selected as VirtualAppliance. For example, if you have a UDR with multiple routes with different NextHopType. And you want to only update the Next hop IP address for the NVA (Network virtual appliance). In that case you can use this module, and update the NVA's IP address. .Parameter ResourceGroupName Name of the ResourceGroupName of the Route Table. .Parameter Name Name of the Route Table. .Switch Name Name of the Route Table. .Parameter logchanges This switch logs the old confiuration of the Route Table. .Example Update-NVAipinRouteTable -ResourceGroupName rgname -Name RouteTableName -NewNVAIP "10.10.10.10" Update-NVAipinRouteTable -ResourceGroupName rgname -Name RouteTableName -NewNVAIP "10.10.10.10" -logchanges #> #------------------------------------------------------------------------------ # # # THIS CODE AND ANY ASSOCIATED INFORMATION ARE PROVIDED “AS IS” WITHOUT # WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT # LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS # FOR A PARTICULAR PURPOSE. THE ENTIRE RISK OF USE, INABILITY TO USE, OR # RESULTS FROM THE USE OF THIS CODE REMAINS WITH THE USER. # #------------------------------------------------------------------------------ function Update-NvaIpinRouteTable { param ( [Parameter(Mandatory = $true)] [string]$ResourceGroupName, [Parameter(Mandatory = $true)] [string]$Name, [Parameter(Mandatory = $true)] [System.Net.IPAddress]$NewNVAIP, [Parameter (Mandatory = $false)] [switch]$logchanges ) $GetRT = Get-AzRouteTable -ResourceGroupName "$ResourceGroupName" -Name $Name $GetRTold = $GetRT if($logchanges -eq $true){ $GetRTold | Out-File "$HOME\$($getrt.Name)-oldRTlog.txt" Write-Host "Old Route Table configuration saved in '$($HOME)'" -ForegroundColor Green } $newrt = $GetRT.Routes | Where-Object { $_.NextHopType -eq "VirtualAppliance" } $count = $newrt.Count for ($i = 0; $i -lt $count; $i++) { $GetRT | Set-AzRouteConfig -Name $newrt.name[$i] -AddressPrefix $newrt.AddressPrefix[$i] -NextHopType VirtualAppliance -NextHopIpAddress $NewNVAIP | Set-AzRouteTable } } Export-ModuleMember -Function Update-NvaIpinRouteTable |