[英]Add many IPs to Azure NSG rule
I have Azure NSG.我有 Azure NSG。 inside i have a rule called "Blocked_IP" I need to automate the process of updating this rule once a day with thousands of new ips (Azure max ip per rule is 4k)
在里面我有一个名为“Blocked_IP”的规则,我需要每天使用数千个新 ip 自动更新此规则的过程(每个规则的 Azure 最大 ip 为 4k)
looking at the documentaiton i have 2 possible commands:查看文档我有 2 个可能的命令:
$ipsarry = Get-Content .\file.txt
az network nsg rule update -g $groupName --nsg-name $NSGName -n $ruleName --source-address-prefix $ipsarry
file.txt will hold the ips. file.txt 将保存 ips。 this will work as long file.txt hold aprox less than 500 ips, as if i add more the command will be a very very long string and there will be an exception.
这将在长 file.txt 保持 aprox 小于 500 ips 时起作用,好像我添加更多命令将是一个非常长的字符串,并且会有一个例外。 i cannot add this in parts as i cannot find a way to append the data, upon each call the old data is deleted.
我无法部分添加它,因为我找不到附加数据的方法,每次调用时都会删除旧数据。
using the other command使用其他命令
$NSG = Get-AzNetworkSecurityGroup -Name 'test' -ResourceGroupName 'Testik'
$Params = @{
'Name' = 'auto_farm_protection4'
'NetworkSecurityGroup' = $NSG
'Protocol' = 'TCP'
'Direction' = 'Inbound'
'Priority' = 500
'SourceAddressPrefix' = "1.1.1.1, 2.2.2.2"
'SourcePortRange' = '*'
'DestinationAddressPrefix' = '*'
'DestinationPortRange' = 3389
'Access' = 'Deny'
}
Add-AzNetworkSecurityRuleConfig @Params | Set-AzNetworkSecurityGroup
will give me the same problem.会给我同样的问题。
looks like google doesnt help me much.看起来谷歌对我帮助不大。 any help would be great.
任何帮助都会很棒。
You can use Set-AzNetworkSecurityRuleConfig -Name <String> -NetworkSecurityGroup <PSNetworkSecurityGroup> -SourceAddressPrefix String[]
.您可以使用
Set-AzNetworkSecurityRuleConfig -Name <String> -NetworkSecurityGroup <PSNetworkSecurityGroup> -SourceAddressPrefix String[]
。 Load the ip address from the text file into String Array (i guess you have a delimiter separating the ip address).将文本文件中的 ip 地址加载到字符串数组中(我猜你有一个分隔符来分隔 ip 地址)。 Finally, pass it to the parameter of SourceAddressPrefix .
最后,将其传递给SourceAddressPrefix的参数。
https://docs.microsoft.com/en-us/powershell/module/az.network/set-aznetworksecurityruleconfig?view=azps-6.6.0 https://docs.microsoft.com/en-us/powershell/module/az.network/set-aznetworksecurityruleconfig?view=azps-6.6.0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.