使用 powershell 将多个 CIDR 添加到 SourceAddressPrefix 到 Azure NSG 规则
Add multiple CIDR to SourceAddressPrefix using powershell to Azure NSG rule
我在使用 powershell 在 Azure 中创建 NSG 规则时尝试将多个 CIDR 添加到 SourceAddressPrefix。我在 运行 Set-AzNetworkSecurityGroup 时收到错误消息,因此它在使用 New-AzNetworkSecurityRuleConfig 创建规则时接受该值。任何人都知道如何解决它?
注意:是的,我知道我可以创建多个规则,但我想尽可能避免这种情况。
使用门户可以正常工作,但使用 Powershell 我收到错误消息。
尝试 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
错误信息:
xxx has invalid Address prefix. Value provided: "10.0.0.0/8","192.168.0.0/16"
尝试 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
错误信息(同样的错误信息):
xxx has invalid Address prefix. Value provided: "10.0.0.0/8","192.168.0.0/16"
New-AzNetworkSecurityRuleConfig
命令需要 String[]
作为 SourceAddressPrefix
参数。 (Ref)
所以以下应该有效:
@("10.0.0.0/8", "192.168.0.0/16")
我在使用 powershell 在 Azure 中创建 NSG 规则时尝试将多个 CIDR 添加到 SourceAddressPrefix。我在 运行 Set-AzNetworkSecurityGroup 时收到错误消息,因此它在使用 New-AzNetworkSecurityRuleConfig 创建规则时接受该值。任何人都知道如何解决它? 注意:是的,我知道我可以创建多个规则,但我想尽可能避免这种情况。
使用门户可以正常工作,但使用 Powershell 我收到错误消息。
尝试 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
错误信息:
xxx has invalid Address prefix. Value provided: "10.0.0.0/8","192.168.0.0/16"
尝试 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
错误信息(同样的错误信息):
xxx has invalid Address prefix. Value provided: "10.0.0.0/8","192.168.0.0/16"
New-AzNetworkSecurityRuleConfig
命令需要 String[]
作为 SourceAddressPrefix
参数。 (Ref)
所以以下应该有效:
@("10.0.0.0/8", "192.168.0.0/16")