Download the example rules.csv file below and update with the fields.

rules.csv

Run the script against the file

param (
  [string] $rule_file
 )
Import-Module CaaS
New-CaasConnection -ApiCredentials (Get-Credential) -Vendor DimensionData -Region Australia_AU -Name MyConnection
$networks = Get-CaasNetworks
$rules = Import-Csv $rule_file
foreach ($rule in $rules) {
    $network = $networks | Where { $_.name -eq $rule.Network } | Select -First 1
    if (-Not $network){
        Write-Error "$($rule.Network) does not exist."
        break;
    }
    if ($rule."Port Range" -eq 'ALL')
    {
        New-CaasAclRule -Network $network -AclRuleName $rule."Rule Name" -Position $rule.Position -Action $rule.Action -Protocol $rule.Protocol -SourceIpAddress $rule."Source IP" -SourceNetmask $rule."Source Netmask" -DestinationIpAddress $rule."Destination IP" -DestinationNetmask $rule."Destination Netmask" -PortRangeType $rule."Port Range" -AclType $rule."ACL Type" 
    }
    elseif ($rule."Port Range" -eq 'EQUAL_TO')
    {
        New-CaasAclRule -Network $network -AclRuleName $rule."Rule Name" -Position $rule.Position -Action $rule.Action -Protocol $rule.Protocol -SourceIpAddress $rule."Source IP" -SourceNetmask $rule."Source Netmask" -DestinationIpAddress $rule."Destination IP" -DestinationNetmask $rule."Destination Netmask" -PortRangeType $rule."Port Range" -AclType $rule."ACL Type" -Port1 $rule."Port 1"
    }
    else
    {
        New-CaasAclRule -Network $network -AclRuleName $rule."Rule Name" -Position $rule.Position -Action $rule.Action -Protocol $rule.Protocol -SourceIpAddress $rule."Source IP" -SourceNetmask $rule."Source Netmask" -DestinationIpAddress $rule."Destination IP" -DestinationNetmask $rule."Destination Netmask" -PortRangeType $rule."Port Range" -AclType $rule."ACL Type" -Port1 $rule."Port 1" -Port2 $rule."Port 2"
    }
}
  • No labels