Synopsis

Creates a virtual network (VNet) in Azure.

Description

The New-AzVirtualNetwork cmdlet creates a virtual network in Azure. You can specify the address space for the virtual network and one or more subnets within it.

Syntax

# Basic Syntax
New-AzVirtualNetwork -Name VNetName -ResourceGroupName ResourceGroupName -Location Location -AddressPrefix "10.0.0.0/16" -Subnet @(@{Name="Subnet01";AddressPrefix="10.0.0.0/24"},@{Name="Subnet02";AddressPrefix="10.0.1.0/24"})

# Example with DNS Servers
New-AzVirtualNetwork -Name MyVNet -ResourceGroupName MyResourceGroup -Location EastUS -AddressPrefix "10.1.0.0/16" -Subnet @{Name='Frontend';AddressPrefix='10.1.0.0/24'} -DnsServer "8.8.8.8","8.8.4.4"

# Example with Tags
New-AzVirtualNetwork -Name MyProductionVNet -ResourceGroupName ProdResourceGroup -Location WestUS -AddressPrefix "192.168.0.0/16" -Subnet @{Name='App';AddressPrefix='192.168.1.0/24'} -Tag @{Environment='Production';Project='MyApp'}

Parameters

Name Type Description Required?
-Name String Specifies the name of the new virtual network. Yes
-ResourceGroupName String Specifies the name of the resource group for the virtual network. Yes
-Location String Specifies the Azure region for the virtual network. Yes
-AddressPrefix String[] Specifies the IP address space for the virtual network as CIDR notation. Can be one or more prefixes. Yes
-Subnet Microsoft.Azure.Commands.Network.Models.PSVirtualNetworkSubnetConfig[] Specifies the subnets to create within the virtual network. Each subnet is defined as a hashtable with 'Name' and 'AddressPrefix' properties. No
-DnsServer String[] Specifies the IP addresses of DNS servers to use for the virtual network. No
-Tag Hashtable Specifies tags as key-value pairs to apply to the virtual network. No
-Force SwitchParameter Suppresses confirmation prompts for potentially disruptive operations. No

Examples

Example 1: Create a basic virtual network


New-AzVirtualNetwork -Name "MyVNet" -ResourceGroupName "MyResourceGroup" -Location "East US" -AddressPrefix "10.0.0.0/16" -Subnet @{Name="Subnet01";AddressPrefix="10.0.0.0/24"}
                        

Example 2: Create a virtual network with multiple subnets and DNS servers


$subnet1 = New-ObjectMicrosoft.Azure.Commands.Network.Models.PSVirtualNetworkSubnetConfig
$subnet1.Name = "Frontend"
$subnet1.AddressPrefix = "10.1.0.0/24"

$subnet2 = New-ObjectMicrosoft.Azure.Commands.Network.Models.PSVirtualNetworkSubnetConfig
$subnet2.Name = "Backend"
$subnet2.AddressPrefix = "10.1.1.0/24"

New-AzVirtualNetwork -Name "MyAdvancedVNet" -ResourceGroupName "MyResourceGroup" -Location "West US" -AddressPrefix "10.1.0.0/16" -Subnet @($subnet1, $subnet2) -DnsServer "8.8.8.8", "8.8.4.4"
                        

Example 3: Create a virtual network with tags


New-AzVirtualNetwork -Name "TaggedVNet" -ResourceGroupName "MyResourceGroup" -Location "Central US" -AddressPrefix "172.16.0.0/16" -Tag @{Project="Phoenix";Owner="DevTeam"}