Add Remove-NSXTDistFirewallSection

This commit is contained in:
William Lam
2019-04-20 12:42:15 -07:00
parent 3134d1acd9
commit fd7429055d

View File

@@ -1185,6 +1185,60 @@ Function Get-NSXTDistFirewallSection {
}
}
Function Remove-NSXTDistFirewallSection {
<#
.NOTES
===========================================================================
Created by: William Lam
Date: 04/20/2019
Organization: VMware
Blog: http://www.virtuallyghetto.com
Twitter: @lamw
===========================================================================
.SYNOPSIS
Removes an NSX-T Distributed Firewall Section
.DESCRIPTION
This cmdlet removes an NSX-T Distributed Firewall Section
.EXAMPLE
Remove-NSXTDistFirewallSection -Id <ID> -Troubleshoot
#>
Param (
[Parameter(Mandatory=$True)]$Id,
[Switch]$Troubleshoot
)
If (-Not $global:nsxtProxyConnection) { Write-error "No NSX-T Proxy Connection found, please use Connect-NSXTProxy" } Else {
$method = "DELETE"
$deleteDistFirewallSectioneURL = $global:nsxtProxyConnection.Server + "/policy/api/v1/infra/domains/cgw/communication-maps/$Id"
if($Troubleshoot) {
Write-Host -ForegroundColor cyan "`n[DEBUG] - $method`n$deleteDistFirewallSectioneURL`n"
}
try {
if($PSVersionTable.PSEdition -eq "Core") {
$requests = Invoke-WebRequest -Uri $deleteDistFirewallSectioneURL -Method $method -Headers $global:nsxtProxyConnection.headers -SkipCertificateCheck
} else {
$requests = Invoke-WebRequest -Uri $deleteDistFirewallSectioneURL -Method $method -Headers $global:nsxtProxyConnection.headers
}
} catch {
if($_.Exception.Response.StatusCode -eq "Unauthorized") {
Write-Host -ForegroundColor Red "`nThe NSX-T Proxy session is no longer valid, please re-run the Connect-NSXTProxy cmdlet to retrieve a new token`n"
break
} else {
Write-Error "Error in removing NSX-T Distributed Firewall Section"
Write-Error "`n($_.Exception.Message)`n"
break
}
}
if($requests.StatusCode -eq 200) {
Write-Host "Successfully removed NSX-T Distributed Firewall Section $Id"
}
}
}
Function Get-NSXTDistFirewall {
<#
.NOTES