Skip to content

Instantly share code, notes, and snippets.

@tonysangha
Last active September 29, 2017 15:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonysangha/2c26dc99bcb855e312f181690823dd40 to your computer and use it in GitHub Desktop.
Save tonysangha/2c26dc99bcb855e312f181690823dd40 to your computer and use it in GitHub Desktop.
One liners commands for PowerNSX
# Retrieve any rules that are configured with either block (deny) or reject in the NSX Distributed Firewall
Get-NsxFirewallSection | Get-NsxFirewallRule | ? {$_.action -eq "deny" -or $_.action -eq "reject"} | ft -autosize
# Retrieve services matching port number
get-nsxservice | ? {$_.element.value -eq "80"} | select name
# Compare NSX Services from two different NSX environments and list the differences based on name
# Not really a one liner I know
$old_services = Get-NsxService -Connection $old_env
$new_services = Get-NsxService -Connection $new_env
Compare-Object $old_services $new_services -Property name -PassThru
# Retrieve interface IP Addresses from all Logical Routers and display in shell
foreach($item in ($int = Get-NsxLogicalRouter | Get-NsxLogicalRouterInterface)){write-host $item.logicalRouterId, "|", $item.name, "|", $item.addressGroups.addressGroup.primaryAddress, "|", $item.addressGroups.addressGroup.subnetMask}
# Reverse the order of a PowerShell array. Useful for importing Firewall rules in the correct order
[array]::Reverse($array)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment