VMware Cloud Community
lizburke
Contributor
Contributor

Invoke-ListGroupForDomain and NSX-T

I created a script in Powershell to push NSX-T DFW rules from a spreadsheet into NSX.  I am searching the NSX manager for the group that was inputted into the spreadsheet for the rule, but I've discovered in production that with 3500 groups in NSX, Powershell can't search all of these.

I'm using Invoke-ListGroupForDomain.  Increasing the PageSize to 1000 helps, but it does not allow me to search the entire list of groups in my Prod manager (3400 groups).   Is there a way to search the entire list of groups?  I noticed in the VMC API, there is a Cursor option, but not in the NSX SDK.

I suppose I could add more if/else statements, but was hoping there might be something I'm missing in the request itself.

 

lizburke_0-1659379261845.png

 

Reply
0 Kudos
6 Replies
LucD
Leadership
Leadership

With the Cursor parameter you can loop through the remaining pages.
Use the result_count property in the 1st returned object to know how many results there are, so you can determine how many times to call and which value(s) to use on the Cursor parameter.

See also KB78858


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
LucD
Leadership
Leadership

As you can see on the reference page for the Invoke-ListGroupForDomain cmdlet, the Cursor parameter expects an integer.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
lizburke
Contributor
Contributor

Oh, got it, thank you!  So once I figure out where the baseline cursor is, I then need to call it X number of times and store it as a new variable in order to search the results, sounds like.

Reply
0 Kudos
LucD
Leadership
Leadership

I think the cursor always starts at 0 on the first call (without the Cursor parameter).
Then you use the result_count property to see how many times you need to call the cmdlet with the Cursor parameter.
As you noticed you can't increment that cursor value with more than 1000 on each successive call


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
lizburke
Contributor
Contributor

Thanks!  Here's the code that I used to make this work.   This manager started at 41000.  I need to test it on a few others but I am assuming I'm going to have to adjust the cursor based on where I'm using this script. 


$AllG1 = Invoke-ListGroupForDomain -DomainId default -Server $n -PageSize 1000
$AllG2 = Invoke-ListGroupForDomain -DomainId default -Server $n -PageSize 1000 -Cursor "00042000"
$AllG3 = Invoke-ListGroupForDomain -DomainId default -Server $n -PageSize 1000 -Cursor "00043000"
$AllG4 = Invoke-ListGroupForDomain -DomainId default -Server $n -PageSize 1000 -Cursor "00044000"

Reply
0 Kudos
LucD
Leadership
Leadership

Not sure why you pass the value to cursor as a String, that should be an Int.
Also, if the 1st call returns groups 0-999, the 2nd call should specify -Cursor 1000, and so on.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos