简体   繁体   中英

Using Powershell to modify azure nsg rule

I have a nsg in azure, inside ths nsg i have a rule which blocks specific ip's. i need to write a powershell script that can add ips in to the specific rule i cannot find a way to do it nor can i find documentation about it..

(Get-AzNetworkSecurityGroup -name blabla-test | Get-AzNetworkSecurityRuleConfig -name "blabla").SourceAddressPrefix

also tried (as seen in doc):

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

there's gotta be a simple way or even just A way

Please try the following:

$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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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