VMware NSX

Update group property in NSX though powershell

  • 1.  Update group property in NSX though powershell

    Posted Jul 23, 2024 06:31 AM

    Hi,

    I'm trying to do someting quite basic, retrieve a group from NSX, change one property and write the group back to NSX again. 

    Apparently when I only write out the property, the API assumes all other values are empty and wipes all properties except the modified one. This means I need to retrieve the entire object, change the property and write out the entire object with all properties including the modified one. 

    Reading the group works fine, group is loaded and property values can be seen.  I can convert the object to json but only depth 1 since the expression object thows an error about duplicates. When just writing the group back, it throws an error that certain expression properties are missing, e.g. expression[0].key or expression[0].value or others.

    Basically I would think that this should work (but it does not):

    $nsx = Connect-NsxServer -Server nsxmgr.lab.local
    $gp = Invoke-ReadGroupForDomain -Server $nsx -DomainId default -GroupId "securitygroup-307"
    Invoke-PatchGroupForDomain -Server $nsx -DomainId default -GroupId $gp.id -Group $gp

    Does anyone have a suggestion how to solve this?  Preferably with powershell but if that's for some reason not possible than python or ansible or other would be fine as well.

    Kind Regards,

    Rob.