New-AzVirtualNetworkSubnetConfig

Creates a virtual network subnet configuration.

Syntax

New-AzVirtualNetworkSubnetConfig
   -Name <String>
   -AddressPrefix <String[]>
   [-NetworkSecurityGroup <PSNetworkSecurityGroup>]
   [-RouteTable <PSRouteTable>]
   [-ServiceEndpoint <String[]>]
   [-ServiceEndpointPolicy <PSServiceEndpointPolicy[]>]
   [-Delegation <PSDelegation[]>]
   [-DefaultProfile <IAzureContextContainer>]
   [<CommonParameters>]
New-AzVirtualNetworkSubnetConfig
   -Name <String>
   -AddressPrefix <String[]>
   [-NetworkSecurityGroupId <String>]
   [-RouteTableId <String>]
   [-ServiceEndpoint <String[]>]
   [-ServiceEndpointPolicy <PSServiceEndpointPolicy[]>]
   [-Delegation <PSDelegation[]>]
   [-DefaultProfile <IAzureContextContainer>]
   [<CommonParameters>]

Description

The New-AzVirtualNetworkSubnetConfig cmdlet creates a virtual network subnet configuration.

Examples

1: Create a virtual network with two subnets and a network security group

New-AzResourceGroup -Name TestResourceGroup -Location centralus

$rdpRule = New-AzNetworkSecurityRuleConfig -Name rdp-rule -Description "Allow RDP" `
   -Access Allow -Protocol Tcp -Direction Inbound -Priority 100 `
   -SourceAddressPrefix Internet -SourcePortRange * `
   -DestinationAddressPrefix * -DestinationPortRange 3389 
    
$networkSecurityGroup = New-AzNetworkSecurityGroup -ResourceGroupName TestResourceGroup `
  -Location centralus -Name "NSG-FrontEnd" -SecurityRules $rdpRule

$frontendSubnet = New-AzVirtualNetworkSubnetConfig -Name frontendSubnet `
    -AddressPrefix "10.0.1.0/24" -NetworkSecurityGroup $networkSecurityGroup

$backendSubnet = New-AzVirtualNetworkSubnetConfig -Name backendSubnet `
    -AddressPrefix "10.0.2.0/24" -NetworkSecurityGroup $networkSecurityGroup

New-AzVirtualNetwork -Name MyVirtualNetwork -ResourceGroupName TestResourceGroup `
    -Location centralus -AddressPrefix "10.0.0.0/16" -Subnet $frontendSubnet,$backendSubnet

This example creates two new subnet configurations using the New-AzVirtualSubnetConfig cmdlet, and then uses them to create a virtual network. The New-AzVirtualSubnetConfig template only creates an in-memory representation of the subnet. In this example, the frontendSubnet has CIDR 10.0.1.0/24 and references a network security group that allows RDP access. The backendSubnet has CIDR 10.0.2.0/24 and references the same network security group.

Parameters

-AddressPrefix

Specifies a range of IP addresses for a subnet configuration.

Type:System.String[]
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-DefaultProfile

The credentials, account, tenant, and subscription used for communication with azure.

Type:Microsoft.Azure.Commands.Common.Authentication.Abstractions.Core.IAzureContextContainer
Aliases:AzContext, AzureRmContext, AzureCredential
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Delegation

List of services that have permission to perform operations on this subnet.

Type:Microsoft.Azure.Commands.Network.Models.PSDelegation[]
Position:Named
Default value:None
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False
-Name

Specifies the name of the subnet configuration to create.

Type:String
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-NetworkSecurityGroup

Specifies a NetworkSecurityGroup object.

Type:PSNetworkSecurityGroup
Position:Named
Default value:None
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False
-NetworkSecurityGroupId

Specifies the ID of a network security group.

Type:String
Position:Named
Default value:None
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False
-RouteTable

Specifies the route table associated with the subnet configuration.

Type:PSRouteTable
Position:Named
Default value:None
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False
-RouteTableId

Specifies the ID of the route table associated with the subnet configuration.

Type:String
Position:Named
Default value:None
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False
-ServiceEndpoint

Service Endpoint Value

Type:System.String[]
Position:Named
Default value:None
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False
-ServiceEndpointPolicy

Service Endpoint Policies

Type:Microsoft.Azure.Commands.Network.Models.PSServiceEndpointPolicy[]
Position:Named
Default value:None
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False

Inputs

String

PSNetworkSecurityGroup

PSRouteTable

System.String[]

Microsoft.Azure.Commands.Network.Models.PSServiceEndpointPolicy[]

Microsoft.Azure.Commands.Network.Models.PSDelegation[]

Outputs

PSSubnet