我有一個天藍色的 nsg,在 nsg 里面我有一個阻止特定 ip 的規則。我需要撰寫一個可以將 ips 添加到特定規則的 powershell 腳本我找不到方法來做到這一點,也找不到關于它的檔案..
(Get-AzNetworkSecurityGroup -name blabla-test | Get-AzNetworkSecurityRuleConfig -name "blabla").SourceAddressPrefix
也嘗試過(如檔案所示):
Get-AzNetworkSecurityGroup -ResourceGroupName "blabla" -name blabla-sg-test | Add-AzNetworkSecurityRuleConfig -Name "testik" -Description "creted automatic" -Protocol "*" -SourcePortRange "*" -DestinationPortRange "*" -SourceAddressPrefix "1.2.3.4" -Access "Deny" -Priority 200 -Direction "Inbound" | Set-AzNetworkSecurityGroup
必須有一個簡單的方法,甚至只是一個方法
uj5u.com熱心網友回復:
請嘗試以下操作:
$NSG = Get-AzNetworkSecurityGroup -Name 'yournsgname' -ResourceGroupName 'nsgrgname'
$Params = @{
'Name' = 'allowRDP'
'NetworkSecurityGroup' = $NSG
'Protocol' = 'TCP'
'Direction' = 'Inbound'
'Priority' = 200
'SourceAddressPrefix' = '1.2.3.4'
'SourcePortRange' = '*'
'DestinationAddressPrefix' = '*'
'DestinationPortRange' = 3389
'Access' = 'Allow'
}
Add-AzNetworkSecurityRuleConfig @Params | Set-AzNetworkSecurityGroup
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/345208.html
