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

Adds a subnet configuration to a virtual network.

Syntax

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

Description

The Add-AzureRmVirtualNetworkSubnetConfig cmdlet adds a subnet configuration to an existing Azure virtual network.

Examples

1: Add a subnet to an existing virtual network

New-AzureRmResourceGroup -Name TestResourceGroup -Location centralus
    $frontendSubnet = New-AzureRmVirtualNetworkSubnetConfig -Name frontendSubnet -AddressPrefix "10.0.1.0/24"
    $virtualNetwork = New-AzureRmVirtualNetwork -Name MyVirtualNetwork -ResourceGroupName TestResourceGroup -Location centralus -AddressPrefix "10.0.0.0/16" -Subnet $frontendSubnet
    Add-AzureRmVirtualNetworkSubnetConfig -Name backendSubnet -VirtualNetwork $virtualNetwork -AddressPrefix "10.0.2.0/24"
    $virtualNetwork | Set-AzureRmVirtualNetwork

This example first creates a resource group as a container of the resources to be created. It then creates a subnet configuration and uses it to create a virtual network. The Add-AzureRmVirtualNetworkSubnetConfig is then used to add a subnet to the in-memory representation of the virtual network. The Set-AzureRmVirtualNetwork command updates the existing virtual network with the new subnet.

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 add.

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

Specifies the VirtualNetwork object in which to add a subnet configuration.

Type:PSVirtualNetwork
Position:Named
Default value:None
Accept pipeline input:True (ByValue)
Accept wildcard characters:False

Optional Parameters

-NetworkSecurityGroup

Specifies a NetworkSecurityGroup object. This cmdlet adds a virtual network subnet configuration to the object that this parameter specifies.

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
Type:PSRouteTable
Position:Named
Default value:None
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False
-RouteTableId
Type:String
Position:Named
Default value:None
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False