Alternatively, we can associate an NSG using Azure PowerShell. In this recipe, we are going to show you how to associate an NSG with a subnet.
Assigning an NSG with PowerShell
Getting ready
Open the PowerShell console and make sure you are connected to your Azure subscription.
How to do it...
To associate an NSG with a subnet, execute the following command:
$vnet = Get-AzureRmVirtualNetwork -Name 'Packt-Script' -ResourceGroupName 'Packt-Networking-Script'
$subnet = Get-AzureRmVirtualNetworkSubnetConfig -VirtualNetwork $vnet -Name BackEnd
$nsg = Get-AzureRmNetworkSecurityGroup...