PowerCLI

Expand all | Collapse all

Powershell scripts to retrieves a list of security groups along with their members in NSX

  • 1.  Powershell scripts to retrieves a list of security groups along with their members in NSX

    Posted Feb 05, 2024 10:38 AM

    Hi All,

    I'm new to powercli and I was trying to export the list of security groups along with their members in excel file. I am trying to run the below script but its not working. I gave domain as default but it threw below error. Any idea what i'm doing wrong here?

    Connect to NSX-T Manager
    Connect-NsxtServer -Server "NSX_URL"

    # Get all security groups and their members
    $securityGroups = Invoke-ListGroupForDomain | ForEach-Object {
    $groupName = $_.display_name
    $groupMembers = Invoke-GetGroupIPMembers -SecurityGroup $_

    [PSCustomObject]@{
    GroupName = $groupName
    Members = $groupMembers.Member
    }
    }

    # Prepare data for CSV
    $csvData = $securityGroups | Select-Object GroupName, Members

    # Export to CSV
    $csvPath = "C:\NSX\NSXT_SecurityGroups.csv"

     

    Pesitm_0-1707129265796.png

     



  • 2.  RE: Powershell scripts to retrieves a list of security groups along with their members in NSX

    Posted Feb 05, 2024 12:16 PM

    If that first line is a comment, you should proceed it with a #

    # Connect to NSX-T Manager

     



  • 3.  RE: Powershell scripts to retrieves a list of security groups along with their members in NSX

    Posted Feb 06, 2024 05:08 AM

    Hi Lucd,
    Sorry, I missed it while copy pasting the script here.



  • 4.  RE: Powershell scripts to retrieves a list of security groups along with their members in NSX

    Posted Feb 06, 2024 07:24 AM

    But does that fix your issue?



  • 5.  RE: Powershell scripts to retrieves a list of security groups along with their members in NSX

    Posted Feb 06, 2024 11:59 AM

    No, it does not.



  • 6.  RE: Powershell scripts to retrieves a list of security groups along with their members in NSX

    Posted Feb 06, 2024 12:03 PM

    Can you show us the errors you are now getting?



  • 7.  RE: Powershell scripts to retrieves a list of security groups along with their members in NSX

    Posted Feb 06, 2024 12:05 PM

    Its the same as the old one.

    Pesitm_0-1707221110229.png

     



  • 8.  RE: Powershell scripts to retrieves a list of security groups along with their members in NSX

    Posted Feb 06, 2024 12:18 PM

    Looks like the connection is not made.
    Check by displaying what is in $global:defaultNsxtServers.


    Did you do the following before?

     

     

    Set-PowerCLIConfiguration  -Scope User -InvalidCertificateAction:Ignore -Confirm:$false

     

     



  • 9.  RE: Powershell scripts to retrieves a list of security groups along with their members in NSX

    Posted Feb 09, 2024 08:52 AM

    I have checked it by running $global:defaultNsxtServers and it displays my NSX server name.

     

    Also, yes i have tried this "Set-PowerCLIConfiguration -Scope User -InvalidCertificateAction:Ignore -Confirm:$false" and it didn't work.



  • 10.  RE: Powershell scripts to retrieves a list of security groups along with their members in NSX

    Posted Feb 09, 2024 08:56 AM

    Did you also connect to the VCSA with Connect-VIServer?
    You can check by displaying the content of $global:defaultVIServer



  • 11.  RE: Powershell scripts to retrieves a list of security groups along with their members in NSX

    Posted Feb 09, 2024 09:02 AM

    Yes, and now it shows the vcenter name. like below

    Name                                 Port                     User
    ----                                      ----                       ----

    Vcenter.com                    443                       admin



  • 12.  RE: Powershell scripts to retrieves a list of security groups along with their members in NSX

    Posted Feb 09, 2024 12:52 PM

    Then I have no clue what is going wrong.

    I suggest you open an SR



  • 13.  RE: Powershell scripts to retrieves a list of security groups along with their members in NSX

    Broadcom Employee
    Posted Dec 02, 2024 07:57 AM

    Hello,

    I have written a simple PowerShell script that will fetch NSX groups and their VM members and output in a JSON or CSV file.

    The scrip wraps NSX API calls to get the groups and VM members.

    https://github.com/antonystefanov/repo-public/tree/main/PowerShell/List-NsxGroups




  • 14.  RE: Powershell scripts to retrieves a list of security groups along with their members in NSX

    Posted Dec 02, 2024 08:21 AM

    Out of curiosity, where can one find the value "default" for the domain-id in this case?

    And does this mean that the Swagger-generated cmdlets like Invoke-ListGroupForDomain do not work?



    ------------------------------


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


    ------------------------------



  • 15.  RE: Powershell scripts to retrieves a list of security groups along with their members in NSX

    Broadcom Employee
    Posted Dec 03, 2024 04:20 AM

    So far in my experience never seen different domain-id than "default"

    I had issues in the past with swagger-generated cdmlets, so decided to wrap API calls.