Created
May 22, 2020 22:25
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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