繁体   English   中英

使用 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参数。 ( 参考)

所以以下应该工作:

@("10.0.0.0/8", "192.168.0.0/16")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM