簡體   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