【发布时间】:2022-01-14 16:43:03
【问题描述】:
我需要一些帮助才能将额外的 IP (122.21.20.3/12) 添加到 Azure 中的一堆 NSG。这是为了允许额外的源地址。 我能够编写一个脚本来帮助我找到受影响的 NSG。我只需要将新 IP 添加到包含另一个类似 IP (122.21.20.2/12) 的 NSG:
$azSubs = Get-AzSubscription
foreach ( $azSub in $azSubs ) {
Set-AzContext -Subscription $azSub | Out-Null
$azNsgs = Get-AzNetworkSecurityGroup
foreach ( $azNsg in $azNsgs ) {
Get-AzNetworkSecurityRuleConfig -NetworkSecurityGroup $azNsg | Where-Object { $_.SourceAddressPrefix -eq '122.21.20.2/12' } | `
Select-Object @{label = 'NSG Name'; expression = { $azNsg.Name } },
@{label = 'Rule Name'; expression = { $_.Name } },
@{label = 'Source IP'; expression = { $_.SourceAddressPrefix } },
@{label = 'Port Range'; expression = { $_.DestinationPortRange } }, Access, Priority, Direction, `
@{label = 'Resource Group Name'; expression = { $azNsg.ResourceGroupName } }
}
}
我可以获得受影响的 NSG 列表。不知道如何将其放入每个的 SourceAddressPrefix 中。 Set-AzNetworkSecurityRuleConfig 是否用于此目的?请问谁有例子吗?
非常感谢!
【问题讨论】:
标签: azure powershell powershell-2.0 powershell-3.0 azure-powershell