Skip to content

Instantly share code, notes, and snippets.

@Zsoldier
Created May 22, 2020 22:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zsoldier/9f1a4dd708d8ea26221713191ca46111 to your computer and use it in GitHub Desktop.
Save Zsoldier/9f1a4dd708d8ea26221713191ca46111 to your computer and use it in GitHub Desktop.
Example on how to call NSX-T Rest API via powershell to delete a route advertisement rule associated w/ a T1.
$NSXMgr=”IPorDNSName”
$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=@{}
$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