Add/Set/Remove NSG rules in ARM mode Azure Powershell

Microsoft Azure

So i ran into a little bit of an issue today, i was trying to find out how i can add more network security rules to a network security group (NSG) in the Azure Resource Manager (ARM) mode under Powershell. Now the old trick under the classic mode of using SET wasn’t working (where the rule will be created if it doesn’t exists) as it was giving me an error that the rule didn’t exists, fair enough ADD would be used for new rules and SET to modify existing once, so i tried that but my rules weren’t saving. After some investigating i found out that you also need to SET (by using the pipeline) the Azure Network Security Group in order for the rules to be saved and since i couldn’t find this information anywhere online here is a blog about it with some examples below.

For Azure Powershell 1.0

Using the Add command to add an additional rule to An Azure ARM NSG:

 

Using the Set command to change the Rule (change the above rule to UDP):

 

Using the Remove command to remove a rule:

 

For Azure Powershell 0.9.8

Using the Add command to add an additional rule to An Azure ARM NSG:

 

Using the Set command to change the Rule (change the above rule to UDP):

 

Using the Remove command to remove a rule:

One thought on “Add/Set/Remove NSG rules in ARM mode Azure Powershell

  1. Hi,

    Thankyou so much for this blog entry! I have spent the last 4 hours banging my head against this trying to work it out.

    I also found out that in classic it was possible to create an address prefix of VIRTUAL_NETWORK but in AzureRM it errors out as below

    SecurityRuleInvalidAddressPrefix: Security rule has invalid Address prefix. Value provided: VIRTUAL_NETWORK

    They appear to have changed it to VirtualNetwork instead…just a quick gotcha in return

Leave a Reply

Your email address will not be published. Required fields are marked *