Skip to content
This repository has been archived by the owner on Oct 28, 2022. It is now read-only.

Commit

Permalink
Fixed error handling missing status
Browse files Browse the repository at this point in the history
  • Loading branch information
nmbradford committed Jan 25, 2017
1 parent 63fb77e commit 66ea393
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Examples/EnableFirewallRuleLogging.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,15 @@ If ( -not $DefaultNsxConnection ) {
throw "Please connect to to NSX first"
}


foreach ( $section in (Get-NsxFirewallSection | ? { $_.name -notmatch 'Default Section Layer3' })) {
$req = Invoke-NsxWebRequest -URI "/api/4.0/firewall/globalroot-0/config/layer3sections/$($section.id)" -method get
$content = [xml]$req.Content
foreach ($rule in $content.section.rule) { $rule.logged = "true" }
$AdditionalHeaders = @{"If-Match"=$req.Headers.ETag}
$response = Invoke-NsxWebRequest -URI "/api/4.0/firewall/globalroot-0/config/layer3sections/$($section.id)" -method put -extraheader $AdditionalHeaders -body $content.section.outerxml
if ( -not $response.StatusCode -eq 200 ) {
throw "Failed putting section $($section.name) ($($section.id)). $($req.StatusCode) : $($req.StatusDescription)"
throw "Failed putting section $($section.name) ($($section.id)). $($response.StatusCode) : $($response.StatusDescription)"
}
else {
write-host "Enabled logging on all rules in Section $($section.name) ($($section.id))"
Expand Down

0 comments on commit 66ea393

Please sign in to comment.