Reputation: 2507
I'm trying to add multiple CIDR to the SourceAddressPrefix when creating a NSG rule in Azure using powershell. I get the error message when running the Set-AzNetworkSecurityGroup so it accepts the value when creating the rule using New-AzNetworkSecurityRuleConfig. Anyone knows how to solve it? Note: Yes I know that I can create multiple rules but I want to avoid that if possible.
Using the portal this works fine but using Powershell I get error message.
Attempt 1:
$rule3 = New-AzNetworkSecurityRuleConfig -Name "In-SandNet-Vnet-Any-Any" `
-Access Allow -Protocol * -Direction Inbound -Priority 1000 -SourceAddressPrefix {"10.0.0.0/8","192.168.0.0/16"} `
-SourcePortRange * -DestinationAddressPrefix VirtualNetwork -DestinationPortRange *
$nsg.SecurityRules.Add($rule3)
Set-AzNetworkSecurityGroup -NetworkSecurityGroup $nsg
Error message:
xxx has invalid Address prefix. Value provided: "10.0.0.0/8","192.168.0.0/16"
Attempt 2:
$rule3 = New-AzNetworkSecurityRuleConfig -Name "In-SandNet-Vnet-Any-Any" `
-Access Allow -Protocol * -Direction Inbound -Priority 1000 -SourceAddressPrefix "10.0.0.0/8,192.168.0.0/16" `
-SourcePortRange * -DestinationAddressPrefix VirtualNetwork -DestinationPortRange *
$nsg.SecurityRules.Add($rule3)
Set-AzNetworkSecurityGroup -NetworkSecurityGroup $nsg
Error message (same error message):
xxx has invalid Address prefix. Value provided: "10.0.0.0/8","192.168.0.0/16"
Upvotes: 2
Views: 1771