Creating Network Security Group using PowerShell

NSG_01

Hi folks!

Today let’s create the network security group that has a very important role within Microsoft Azure. It works at layer 4, where we can communicate ports and IPs between internal or external networks through a VPN.

Now let’s assign the following variables:

$NSGName=”NSG-VM-01″
$RGName= “RG_GETPRACTICAL”
$LOCATION= “UKSOUTH”

NSG_02

Next, we will create a variable with the name of the port and which rule will be used. In this case, I am creating an “NSG” for RDP access.

$RULES = New-AzNetworkSecurityRuleConfig -Name ‘Default-Allow-RDP’ -Direction Inbound -Priority 1000 -Access Allow -SourceAddressPrefix ‘*’  -SourcePortRange ‘*’ -DestinationAddressPrefix ‘*’ -DestinationPortRange 3389 -Protocol TCP

NSG_03

Now let’s create the NSG, using the following command.

$NSG = New-AzNetworkSecurityGroup -Name $NSGName -ResourceGroupName $RGName -Location $LOCATION -SecurityRules $RULES

NSG_04

Your NSG was successfully created.

NSG_05

Thanks guys and until the next post, where I will demonstrate how to create a virtual machine using all these commands at once.

Joao Paulo Costa

Author: João Paulo Costa

MCP, MCT, MCSA, MCITP, MCTS, MS, Azure Solutions Architect, Azure Administrator, Azure Network Engineer, Azure Fundamentals, Microsoft 365 Enterprise Administrator Expert, Microsft 365 Messaging Administrator, ITIL v3.

3 thoughts on “Creating Network Security Group using PowerShell”

  1. Thanks so much for providing individuals with remarkably special opportunity to read from here. It is usually so excellent and also stuffed with amusement for me personally and my office acquaintances to visit the blog really thrice per week to read through the latest guides you will have. And definitely, I am also actually fascinated concerning the great tips you give. Some 2 areas in this posting are certainly the most effective I have ever had.

    Like

Leave a reply to gralion torile Cancel reply