簡體   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