Azure Powershell无法创建具有多个端口的NSG规则

时间:2019-06-07 12:08:01

标签: azure powershell

我正在向NSG添加一个安全规则,该规则允许访问端口4239、1128、1129。通过Azure门户,它可以工作。通过Powershell,它拒绝了。

我正在使用以下代码来获取NSG,添加安全规则并更新NSG。

$nsg = Get-AzNetworkSecurityGroup -Name "BITH-DEV-T1NSG" - 
ResourceGroupName "RG-BITH-HANA-POC"

$nsg | Add-AzNetworkSecurityRuleConfig -Name "SUM6" -Description "Allow 
SUM" -Access "Allow" -Protocol * -Direction "Inbound" -Priority "105" - 
SourceAddressPrefix * -SourcePortRange * -DestinationAddressPrefix * - 
DestinationPortRange "1128,1129,4239"

$nsg | Set-AzNetworkSecurityGroup

更新NSG时,出现以下错误。

Set-AzNetworkSecurityGroup : Security rule has invalid Port range. Value 
provided: 4239,1128,1129. Value should be an integer OR integer range 
with '-' delimiter.Valid range 0-65535.

是否可以通过Powershell向NSG添加自定义范围?

1 个答案:

答案 0 :(得分:0)

您应该提供一个数组作为输入,而不是带逗号的字符串:

-DestinationPortRange (1128, 1129, 4239)

或使用"1128", "1129", "4239"(如果它不会自动将它们强制转换为字符串)。 DestinationPortRange接受一个数组。

阅读:https://docs.microsoft.com/en-us/powershell/module/az.network/add-aznetworksecurityruleconfig?view=azps-2.2.0#parameters

相关问题