无法通过 powershell 删除 NSG 规则
Can't delete NSG rule through powershell
我正在尝试创建一个 Runbook 以通过 Azure Automation 运行book 删除对特定 NSG 组的任何添加。
为此,我有以下脚本:
$nsg_item = Get-AzureRmNetworkSecurityGroup -Name $NSG -ResourceGroupName $ResourceGroupName
Write-Output ("NSG content before removal: " + $nsg_item)
Remove-AzureRmNetworkSecurityRuleConfig -Name $rule -NetworkSecurityGroup $nsg_item
当我这样做时,运行本书执行时没有任何问题,脚本的输出显示规则已被删除
来自核供应国集团。
之前:
SecurityRules : {Port_443, default-allow-ssh, Port_8080
之后:
SecurityRules : {Port_443, default-allow-ssh}
但是,如果我继续访问相关的 NSG,规则仍然存在并启用。我试图通过 Azure 中的 Powershell CLI 运行 相同的脚本,但同样的事情发生了。
知道可能是什么问题吗?
您需要将结果通过管道传输到 Set-AzureRmNetworkSecurityGroup
cmdlet:
Remove-AzureRmNetworkSecurityRuleConfig -Name $rule -NetworkSecurityGroup $nsg_item | Set-AzureRmNetworkSecurityGroup
我正在尝试创建一个 Runbook 以通过 Azure Automation 运行book 删除对特定 NSG 组的任何添加。
为此,我有以下脚本:
$nsg_item = Get-AzureRmNetworkSecurityGroup -Name $NSG -ResourceGroupName $ResourceGroupName
Write-Output ("NSG content before removal: " + $nsg_item)
Remove-AzureRmNetworkSecurityRuleConfig -Name $rule -NetworkSecurityGroup $nsg_item
当我这样做时,运行本书执行时没有任何问题,脚本的输出显示规则已被删除 来自核供应国集团。
之前:
SecurityRules : {Port_443, default-allow-ssh, Port_8080
之后:
SecurityRules : {Port_443, default-allow-ssh}
但是,如果我继续访问相关的 NSG,规则仍然存在并启用。我试图通过 Azure 中的 Powershell CLI 运行 相同的脚本,但同样的事情发生了。
知道可能是什么问题吗?
您需要将结果通过管道传输到 Set-AzureRmNetworkSecurityGroup
cmdlet:
Remove-AzureRmNetworkSecurityRuleConfig -Name $rule -NetworkSecurityGroup $nsg_item | Set-AzureRmNetworkSecurityGroup