andres-canello / GlobalSecureAccess.ps

MIT License
2 stars 0 forks source link

When using input file and variables unable to specify both TCP,UDP protocol #3

Open Altec6 opened 2 months ago

Altec6 commented 2 months ago

When using an input file and and variables and trying to pass in the value of "TCP,UDP" to set both protocols the command fails the ValidateSet. It appears the validation for protocol is set to:

.. [Parameter(Mandatory = $False)] [ValidateSet("TCP", "UDP")] [string] $Protocol, ..

I have tested modifying this value to be the below: .. [Parameter(Mandatory = $False)] [ValidateSet("TCP", "UDP","TCP,UDP")] [string] $Protocol, ..

I have tested this in the New-GSAPrivateAccessAppNetworkSegment.ps1 and Set-GSAPrivateAccessAppNetworkSegment.ps1 functions for my use case and it seems to function well.

andres-canello commented 2 months ago

Hello!, The reason that fails is the parameter expects and array, and as you found out the string "TCP,UDP" is not one of the accepted values. The way to resolve this is to convert the values to an array before passing it to the command, like this:

$csvFile = "C:\temp\AppSegments.csv"

# Assuming the CSV file has columns named 'clientID', 'iprange', 'ports', 'protocol', 'type'
$variables = Import-Csv $csvFile

# Loop through each row of the CSV and execute the command for each set of variables
foreach ($variable in $variables) {
    $clientID = $variable.clientID
    $iprange = $variable.iprange
    $ports = $variable.ports -split ","
    $protocol = $variable.protocol -split ","
    $type = $variable.type

    # Execute the command
    Get-GSAPrivateAccessApp $clientID | New-GSAPrivateAccessAppNetworkSegment -DestinationHost $iprange -Ports $ports -Protocol $protocol -DestinationType $type -debug
}

I've added the above script and a sameple csv to the \Samples folder in the module.