VMware Networking Community
TarunGuptaAccen
Enthusiast
Enthusiast

NSX-t 3.1.2 Get Groups and services are where used

Hi Team ,

I am asking 2 questions here  :

1 . I can see in GUI where Groups and services are  used when i click on "where used ". How can i get the  same data in powercli  or any other way ?

TarunGuptaAccen_0-1641236233457.png

 

 

I have tried 

GET https://10.231.232.201/policy/api/v1/infra/domains/default/groups but i cant find the where used feild..

 

2.  how can i get the list of all Groups  in NSX-t ..I have 9507 Groups  as you can see in below  screenshot  but API and power NSX does not list all the Groups .. 

TarunGuptaAccen_0-1641236867118.png

 

 API only gives me some groups where resource_type is Group 

$Groups=Invoke-RestMethod -Uri "https://10.231.232.201/policy/api/v1/infra/domains/default/groups" -Headers $Headers -Method Get

$Groups.results.count  =1000   (  why only 1000 ? ) ..I have attached API output in case required.

 

same with PowerNSX module ...

$nsgroupsvc = Get-NsxtService -Name com.vmware.nsx.ns_groups
$nsgroups = $nsgroupsvc.list()
$nsgroups.results
$nsgroups.results.count
50

 

Tarun Gupta

 

Reply
0 Kudos
4 Replies
BassMCN
Contributor
Contributor

Hi Tarun,

I had the same problem. It a limitation of API.

I find a way to list all. 

You need to use the propertie named cursor and iterate trough them until it become = to null. At that moment, you know that you reach the end of list.

Im using a simple While loop to iterate though list . 

 

Reply
0 Kudos
DrFranco
Contributor
Contributor

I have this issue also, can you share your while loop code? I'd like to see how you iterated through the list.

Thanks!

Reply
0 Kudos
DrFranco
Contributor
Contributor

can you share your while loop?

Reply
0 Kudos
DrFranco
Contributor
Contributor

I figured this out with the help of ChatGPT so I thought I'd share here.

# Connect to the NSX-T Manager
Connect-NsxtServer nsxmanager.name.put.here

# Get the NSX-T service for NS groups
$nsgroupsvc = Get-NsxtService -Name com.vmware.nsx.ns_groups

# Retrieve the first page of NS groups
$nsgroups = $nsgroupsvc.list()

# Loop through each page of NS groups
while ($nsgroups.results) {
    # Output the NS groups
    $nsgroups.results | Format-Table -Autosize -Property id, display_name, members

    # Check if there are more NS groups to retrieve
    if ($nsgroups.cursor) {
        # Get the next page of NS groups
        $nsgroups = $nsgroupsvc.list($nsgroups.cursor)
    } else {
        # No more NS groups to retrieve
        break
    }
}

# Disconnect from the NSX-T Manager
Disconnect-NsxtServer
Reply
0 Kudos