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

ValidateSecurityGroupMember relies on defaultNSXConnection #476

Open neilcat opened 6 years ago

neilcat commented 6 years ago

Cmdlets like Add-NsxSecurityGroupMember fail if defaultNSXConnection is not set as they call ValidateSecurityGroupMember which relies on this.

Eg.

PowerCLI C:\> $CustomConnection = Connect-NsxServer -vCenterServer myvcenter.company.com -DefaultConnection:$False -VIDefaultConnection:$false -ViWarningAction Ignore
PowerCLI C:\> $NwIpSet = New-NsxIpSet -Name test-IPset -IPAddresses 172.16.20.0/24 -Connection $CustomConnection

PowerCLI C:\> Get-NsxSecurityGroup Custom_Subnet_All -Connection $CustomConnection| Add-NsxSecurityGroupMember -member $NwIpSet -Connection $CustomConnection
Add-NsxSecurityGroupMember : Cannot validate argument on parameter 'Member'. The variable '$defaultNSXConnection' cannot be retrieved because it has not been set.
At line:1 char:112
+ ... Member -member $NwIpSet -Connection $CustomConnection
+                    ~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Add-NsxSecurityGroupMember], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Add-NsxSecurityGroupMember
alagoutte commented 6 years ago

Hi Neil,

yes, i confirm the issue

it coming because there is a "check" for check if it is a valid NsxMemberType (using Get-NsxSecurityGroupMemberTypes cmdlets) but thiere is no -Connection option for when there is the check...

You can use before your add-nsxSecurityGroupMember, this command $script:NsxMemberTypes = Get-NsxSecurityGroupMemberTypes -Connection $customconnection

it will work !