PowerShell is a command-line shell and scripting language based on the .NET Framework. It's often used by system administrators to automate tasks and manage operating systems. Azure PowerShell is a PowerShell module that allows us to automate and manage Azure resources. Azure PowerShell is also very often used to automate deployment tasks and can also be used to deploy a new Azure Virtual Network.
Creating a virtual network with PowerShell
Getting ready
Before we start, we need to connect to the Azure subscription from a PowerShell console. Here's the command to do this:
Connect-AzureRmAccount
This will open a new window where we need to input the credentials for the Azure subscription.
Afterward, we need to create a resource group where our virtual network will be deployed:
New-AzureRmResourceGroup -name 'Packt-Networking-Script' -Location 'westeurope'
The output should be similar to the following screenshot:
How to do it...
Deploying Azure Virtual Network is done in a single script. We need to define parameters for the resource group, location, name, and address range. Here is an example script:
New-AzureRmVirtualNetwork -ResourceGroupName 'Packt-Networking-Script' -Location 'westeurope' -Name 'Packt-Script' -AddressPrefix 10.11.0.0/16
You should receive the following output:
How it works...
The difference between deploying of a virtual network from the portal and using PowerShell is that no subnet needs to be defined in PowerShell. The subnet is deployed in a separate command that can be executed either when you are deploying a virtual network or later on. We are going to see this command in the Adding subnets with PowerShell recipe.