vmware-archive / powernsx

PowerShell module that abstracts the VMware NSX-v API to a set of easily used PowerShell functions
173 stars 89 forks source link

Get-NSXFirewallSection returns only 1 section #624

Closed guptatarun1989 closed 4 years ago

guptatarun1989 commented 4 years ago

Hi team , Let me know if i am doing wrong ? . I have 4 Universal sections with same name "GHGHGHG" .

image image

When i do below , i only get 1 section instead i should get 4 . $foundsection =@(Get-NsxFirewallSection |Where-Object {$_.name -eq "GHGHGHG"})

or image

I have tried this code . but again i am getting only 1 Section ..why is that ?

$Global:NSXSection= @(Get-NsxFirewallSection | ? {$_.managedby -eq "universalroot-0"} ) $foundsection=@() foreach( $i in $Global:NSXSection) { if ($i.name -eq "GHGHGHG") {

$global:Sectionfound=0 $Global:sectionruledisplay=@() $foundsection += $i } } image

guptatarun1989 commented 4 years ago

any comment on this please?

dcoghlan commented 4 years ago
PS C:\Users\Administrator> Get-NsxFirewallSection | select name,id

name                   id
----                   --
GHGHGHG                761b84a7-074e-458d-9ebe-d160650e032c
GHGHGHG                82055770-2332-4e0e-b103-208a5c1188f6
GHGHGHG                0033954c-8f05-4e23-bd31-917c323ee31f
GHGHGHG                766c5384-5e58-4987-b468-5c4f3af7a0e3
Foo                    1007
Moe                    1006
Curly                  1005
Larry                  1004
Default Section Layer3 1003

PS C:\Users\Administrator> Get-NsxFirewallSection | ? {$_.name -eq "GHGHGHG"} | ft

id                                   name    generationNumber timestamp     managedBy       tcpStrict stateless useSid type
--                                   ----    ---------------- ---------     ---------       --------- --------- ------ ----
761b84a7-074e-458d-9ebe-d160650e032c GHGHGHG 1591358245144    1591358245144 universalroot-0 false     false     false  LAYER3
82055770-2332-4e0e-b103-208a5c1188f6 GHGHGHG 1591358243526    1591358243526 universalroot-0 false     false     false  LAYER3
0033954c-8f05-4e23-bd31-917c323ee31f GHGHGHG 1591358241662    1591358241662 universalroot-0 false     false     false  LAYER3
766c5384-5e58-4987-b468-5c4f3af7a0e3 GHGHGHG 1591358235486    1591358235486 universalroot-0 false     false     false  LAYER3
guptatarun1989 commented 4 years ago

Hi @dcoghlan , Thanks for your reply . I have tried the above Combination many times. Please see as i tried today with section name "Tarun1" . I have 3 universal section named "Tarun1 " , but is showing me only 2 sections as output

image

image

image

Another thing i want to highlight is that in my above comment earlier when i ran the command Get-NsxFirewallSection |Where-Object {$.name -eq "GHGHGHG"}) i only got 1 section as output , now when i run Get-NsxFirewallSection |Where-Object {$.name -eq "Tarun1}) , i am getting 2 sections although i have 3 sections .

When i saw you post, i am not sure what am i doing wrong ? .. i have tried reconnecting to NSXServer, published and refresh section many times , tried both VmwarePowerCLI as well as Powershell ISE. Anything you feel i am doing wrong here?

dcoghlan commented 4 years ago

Try this one. You might have some non-printing characters in the name which is causing funny buggers

Get-NsxFirewallSection | ? {$_.name -match "Tarun1"}

also what version are you using?



Version  Path                                                                              Author        CompanyName
-------  ----                                                                              ------        -----------
3.0.1174 C:\Users\Administrator\Documents\WindowsPowerShell\Modules\PowerNSX\PowerNSX.psm1 Nick Bradford VMware```
guptatarun1989 commented 4 years ago

@dcoghlan : Thanks a lot .. .. I got the root cause when i ran "Get-NsxFirewallSection | ? {$_.name -match "Tarun1"}"

One of my section it is ending with extra space . When i click my mouse on other section "Tarun1" ,mouse pointer lands after 1 but in one section there is a space after 1 , i removed that space now everything is working .

image

.. i never thought it count's space while some-one tires to re-name a section and may end up giving a extra space in the end ..

Thanks a lot :) @dcoghlan

Tarun Gupta