Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Example on how to call NSX-T Rest API via powershell to delete a route advertisement rule associated w/ a T1.
$Credential = Get-Credential #Must be Enterprise Admin role. Typically “admin”
$skipcertcheck = $true
$AuthMethod = “Basic”
$TargetRouterName = “LeeroyJenkinsT1”
#To get target logical router id
$lrdata = Invoke-restmethod -Uri “https://$($NSXMgr)/api/v1/logical-routers” -Method GET -Credential $Credential -SkipCertificateCheck:$skipcertcheck -Authentication:$AuthMethod
$routerid = ($lrdata.results | Where-Object {$_.display_name -eq $TargetRouterName}).id
#To get revision number:
$ruledata = Invoke-restmethod -Uri “https://$($NSXMgr)/api/v1/logical-routers/$($routerid)/routing/advertisement/rules” -Method GET -Credential $Credential -SkipCertificateCheck:$skipcertcheck -Authentication:$AuthMethod
$revision = $ruledata._revision
#To clear routing advertisement rules table of target router.
$headers.Add("content-type", "application/json")
$headers.Add("x-allow-overwrite", "true")
Invoke-restmethod -Uri “https://$($NSXMgr)/api/v1/logical-routers/$($routerid)/routing/advertisement/rules” -Method PUT -Headers $headers -Credential $Credential -SkipCertificateCheck:$skipcertcheck -Authentication:$AuthMethod -ContentType 'application/json' -Body (‘{ "_revision": "’ + $Revision + ‘"}’)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.