Skip to main content

PowerNSX | Add mulitple static route in NSX Edge

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

Comments

Popular posts from this blog

Network Migration | VLAN to VXLAN

NSX-T | Getting Started with PowerCLI

NSX-T | Security

Automate Power on Operations using PS