New-​Azure​Rm​Virtual​Network​Subnet​Config

Creates a virtual network subnet configuration.

Syntax

New-AzureRmVirtualNetworkSubnetConfig
   -AddressPrefix <String>
   -Name <String>
   [-NetworkSecurityGroup <PSNetworkSecurityGroup>]
   [-RouteTable <PSRouteTable>]
   [<CommonParameters>]
New-AzureRmVirtualNetworkSubnetConfig
   -AddressPrefix <String>
   -Name <String>
   [-NetworkSecurityGroupId <String>]
   [-RouteTableId <String>]
   [<CommonParameters>]

Description

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

Examples

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

New-AzureRmResourceGroup -Name TestResourceGroup -Location centralus
    $rdpRule = New-AzureRmNetworkSecurityRuleConfig -Name rdp-rule -Description "Allow RDP" 
    -Access Allow -Protocol Tcp -Direction Inbound -Priority 100 -SourceAddressPrefix 
    Internet -SourcePortRange * -DestinationAddressPrefix * -DestinationPortRange 3389
    $networkSecurityGroup = New-AzureRmNetworkSecurityGroup -ResourceGroupName 
    TestResourceGroup -Location centralus -Name "NSG-FrontEnd" -SecurityRules $rdpRule
    $frontendSubnet = New-AzureRmVirtualNetworkSubnetConfig -Name frontendSubnet 
    -AddressPrefix "10.0.1.0/24" -NetworkSecurityGroup $networkSecurityGroup
    $backendSubnet = New-AzureRmVirtualNetworkSubnetConfig -Name backendSubnet -AddressPrefix 
    "10.0.2.0/24" -NetworkSecurityGroup $networkSecurityGroup
    New-AzureRmVirtualNetwork -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-AzureRmVirtualSubnetConfig cmdlet, and then uses them to create a virtual network. The New-AzureRmVirtualSubnetConfig 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.

Required Parameters

-AddressPrefix

Specifies a range of IP addresses for a subnet configuration.

Type:String
Position:Named
Default value:None
Accept pipeline input:False
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

Optional Parameters

-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