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

标签 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?

最佳答案

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

-DestinationPortRange (1128, 1129, 4239)

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

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

关于Azure Powershell 不创建具有多个端口的 NSG 规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56494032/

相关文章:

azure - 在不同的 Azure 环境中创建单独的 Azure Key Vault 是否合适?

powershell - X509Store.Open()引发异常

powershell - 如何将文件夹移动到具有要移动的文件夹的第一个字符名称的子文件夹中,并支持文件夹名称中的 Unicode 字符?

arrays - 了解晦涩的 PowerShell 数组语法 : Why does @(11. .20+1) 有效,而 @(1+11..20) 无效?我怎样才能实现后者?

windows - Connect-AzAccount 更改浏览器

azure - 用于辅助角色配置的 WaIISHost.exe.config 与 app.config

Azure Powershell 从 CSV 文件标记 VM

iis-7 - 是否可以从 Azure ServiceConfiguration 文件读取 IIS 重写规则?

python - 从 Azure Key Vault 下载 .PEM 格式的公钥

powershell - 我应该使用 [ValidateNotNullOrEmpty()] 然后在函数中查找空格,还是使用 [ValidateScript(...)]?