Keithlynn R
Keithlynn R

Reputation: 3

AZURE: Change the PRIORITY Rule configuration in a network security group via PowerShell

I cannot make it work, please review below code

$nsg = Get-AzureRmNetworkSecurityGroup -Name MYNSG001 -ResourceGroupName MYRG

$nsg | Get-AzureRmNetworkSecurityRuleConfig -Name MYRULE

Set-AzureRmNetworkSecurityRuleConfig -Name MYRULE -NetworkSecurityGroup $nsg -Priority 110

Thanks in advance

Upvotes: 0

Views: 752

Answers (1)

Joy Wang
Joy Wang

Reputation: 42043

There are two points that you missed:

  1. You need to use Set-AzureRmNetworkSecurityGroup at last.

  2. You need to provide all required security rule parameters, not only Priority, it is not allowed when using Set-AzureRmNetworkSecurityGroup.

You could try my sample command below, it works fine on my side.

$nsg = Get-AzureRmNetworkSecurityGroup -Name "NSG name" -ResourceGroupName "<resource group name>"
$nsg | Get-AzureRmNetworkSecurityRuleConfig -Name "Port_8080" 
$config = Set-AzureRmNetworkSecurityRuleConfig -Name "Port_8080" -NetworkSecurityGroup $nsg -Priority 110 -Protocol "*" -Access "Allow" -Direction "Inbound" -SourceAddressPrefix "Internet" -SourcePortRange "*" -DestinationAddressPrefix "*" -DestinationPortRange "8080"
$config | Set-AzureRmNetworkSecurityGroup

enter image description here

For more details about the parameters, refer to this link.

Upvotes: 1

Related Questions