azure-powershell icon indicating copy to clipboard operation
azure-powershell copied to clipboard

How to add security rules to an existing Network Security Group?

Open timmayg opened this issue 10 years ago • 8 comments

Hi all,

I cannot figure out how to add a rule to an NSG that already exists...

I've tried both New-AzureRmNetworkSecurityRuleConfig and Add-AzureRmNetworkSecurityRuleConfig and it appears to create the object with a Provisioning State of null. Then I've tried to Set-AzureRmNetworkSecurityRuleConfig. However the rule never gets added....

Can someone please help me understand this process?

Thank you !

timmayg avatar Dec 15 '15 13:12 timmayg

@deepakswifty can you provide some guidance here?

devigned avatar Dec 15 '15 13:12 devigned

Hi @timmayg,

Add-AzureRmNetworkSecurityRuleConfig and Set-AzureRmNetworkSecurityRuleConfig create in-memory objects. You would have to call Set-AzureRmNetworkSecurityGroup to commit your state to the service. For example.

$nsg = Get-AzureRmNetworkSecurityGroup $nsg | Add-AzureRmNetworkSecurityRuleConfig $nsg | Set-AzureRmNetworkSecurityGroup

(or) if you want to put them all in one line

Get-AzureRmNetworkSecurityGroup | Add-AzureRmNetworkSecurityRuleConfig | | Set-AzureRmNetworkSecurityGroup

Thanks, Deepak.

DeepakRajendranMsft avatar Dec 15 '15 19:12 DeepakRajendranMsft

Hi @deepakswifty Thanks very much! This worked perfectly.

timmayg avatar Jan 05 '16 14:01 timmayg

So this post was made back in December of 2015 and yet the documentation on this cmdlet still has not been updated with even one example: https://msdn.microsoft.com/en-us/library/mt603772.aspx

ronbok avatar Apr 19 '16 01:04 ronbok

Previously reported https://github.com/Azure/azure-powershell/issues/70 Will track from that issue. Thanks.

markjbrown avatar May 19 '16 17:05 markjbrown

I wonder what it takes to add complete contextual examples, best practices for each of the PS commands. Or in case of NSG rules - adding a requirement "please run set command after doing everything in memory". Even now https://msdn.microsoft.com/en-us/library/mt603772.aspx is not updated. Can we add the example ?

gnot avatar Jun 15 '16 17:06 gnot

Is there a way to update an existing NSG with new rules in .JSON format?

1scscott avatar Dec 21 '16 18:12 1scscott

+1 to the json question for existing NSG's by @1scscott.

JeremyTBradshaw avatar Jul 21 '18 13:07 JeremyTBradshaw