繁体   English   中英

使用 Powershell 修改 azure nsg 规则

[英]Using Powershell to modify azure nsg rule

我有一个天蓝色的 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

必须有一个简单的方法,甚至只是一个方法

请尝试以下操作:

$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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM