Good Day Folks,
During one of the activity, I had a requirement to put multiple (20-25) static routes on NSX edge and doing it one by one and manually is a headache, you know that. right?
So, I thought to do it through power NSX. Below is the code-
#Start here
Connect-NSXServer -NSXserver 192.168.110.42
$nsxedges = (Get-nsxedge -objectid edge-3).id
$subnets = '172.16.32.0/24','172.22.12.0/24' #add all the network which you want to add in static route
$nexthop = '8.8.8.8'
Foreach($subnet in $subnets){
Foreach($nsxedge in $nsxedges){
Get-NsxEdge -ObjectId $nsxedge | Get-NsxEdgerouting | New-NsxEdgeStaticRoute -vNic 0 -Network $subnet -NextHop $nexthop -MTU 9000 -AdminDistance 1 -Confirm:$false
}
}
#End here
Refer to below output for an example
Hope it will help you. Let me know if any doubt or any error.
Thank you,
vCloudNotes
During one of the activity, I had a requirement to put multiple (20-25) static routes on NSX edge and doing it one by one and manually is a headache, you know that. right?
So, I thought to do it through power NSX. Below is the code-
#Start here
Connect-NSXServer -NSXserver 192.168.110.42
$nsxedges = (Get-nsxedge -objectid edge-3).id
$subnets = '172.16.32.0/24','172.22.12.0/24' #add all the network which you want to add in static route
$nexthop = '8.8.8.8'
Foreach($subnet in $subnets){
Foreach($nsxedge in $nsxedges){
Get-NsxEdge -ObjectId $nsxedge | Get-NsxEdgerouting | New-NsxEdgeStaticRoute -vNic 0 -Network $subnet -NextHop $nexthop -MTU 9000 -AdminDistance 1 -Confirm:$false
}
}
#End here
Refer to below output for an example
Hope it will help you. Let me know if any doubt or any error.
Thank you,
vCloudNotes
0 Comments:
Post a Comment