New-AzureRmVirtualNetworkSubnetConfig

Creates a virtual network subnet configuration.

Warning

The AzureRM PowerShell module has been officially deprecated as of February 29, 2024. Users are advised to migrate from AzureRM to the Az PowerShell module to ensure continued support and updates.

Although the AzureRM module may still function, it's no longer maintained or supported, placing any continued use at the user's discretion and risk. Please refer to our migration resources for guidance on transitioning to the Az module.

Syntax

New-AzureRmVirtualNetworkSubnetConfig
   -Name <String>
   -AddressPrefix <System.Collections.Generic.List`1[System.String]>
   [-NetworkSecurityGroup <PSNetworkSecurityGroup>]
   [-RouteTable <PSRouteTable>]
   [-ServiceEndpoint <System.Collections.Generic.List`1[System.String]>]
   [-ServiceEndpointPolicy <System.Collections.Generic.List`1[Microsoft.Azure.Commands.Network.Models.PSServiceEndpointPolicy]>]
   [-Delegation <System.Collections.Generic.List`1[Microsoft.Azure.Commands.Network.Models.PSDelegation]>]
   [-DefaultProfile <IAzureContextContainer>]
   [<CommonParameters>]
New-AzureRmVirtualNetworkSubnetConfig
   -Name <String>
   -AddressPrefix <System.Collections.Generic.List`1[System.String]>
   [-NetworkSecurityGroupId <String>]
   [-RouteTableId <String>]
   [-ServiceEndpoint <System.Collections.Generic.List`1[System.String]>]
   [-ServiceEndpointPolicy <System.Collections.Generic.List`1[Microsoft.Azure.Commands.Network.Models.PSServiceEndpointPolicy]>]
   [-Delegation <System.Collections.Generic.List`1[Microsoft.Azure.Commands.Network.Models.PSDelegation]>]
   [-DefaultProfile <IAzureContextContainer>]
   [<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.

Parameters

-AddressPrefix

Specifies a range of IP addresses for a subnet configuration.

Type:List<T>[String]
Position:Named
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-DefaultProfile

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

Type:IAzureContextContainer
Aliases:AzureRmContext, AzureCredential
Position:Named
Default value:None
Required:False
Accept pipeline input:False
Accept wildcard characters:False

-Delegation

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

Type:List<T>[PSDelegation]
Position:Named
Default value:None
Required:False
Accept pipeline input:True
Accept wildcard characters:False

-Name

Specifies the name of the subnet configuration to create.

Type:String
Position:Named
Default value:None
Required:True
Accept pipeline input:False
Accept wildcard characters:False

-NetworkSecurityGroup

Specifies a NetworkSecurityGroup object.

Type:PSNetworkSecurityGroup
Position:Named
Default value:None
Required:False
Accept pipeline input:True
Accept wildcard characters:False

-NetworkSecurityGroupId

Specifies the ID of a network security group.

Type:String
Position:Named
Default value:None
Required:False
Accept pipeline input:True
Accept wildcard characters:False

-RouteTable

Specifies the route table associated with the subnet configuration.

Type:PSRouteTable
Position:Named
Default value:None
Required:False
Accept pipeline input:True
Accept wildcard characters:False

-RouteTableId

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

Type:String
Position:Named
Default value:None
Required:False
Accept pipeline input:True
Accept wildcard characters:False

-ServiceEndpoint

Service Endpoint Value

Type:List<T>[String]
Position:Named
Default value:None
Required:False
Accept pipeline input:True
Accept wildcard characters:False

-ServiceEndpointPolicy

Service Endpoint Policies

Type:List<T>[PSServiceEndpointPolicy]
Position:Named
Default value:None
Required:False
Accept pipeline input:True
Accept wildcard characters:False

Inputs

String

PSNetworkSecurityGroup

PSRouteTable

List<T>[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]

List<T>[[Microsoft.Azure.Commands.Network.Models.PSServiceEndpointPolicy, Microsoft.Azure.Commands.Network, Version=6.7.0.0, Culture=neutral, PublicKeyToken=null]]

List<T>[[Microsoft.Azure.Commands.Network.Models.PSDelegation, Microsoft.Azure.Commands.Network, Version=6.7.0.0, Culture=neutral, PublicKeyToken=null]]

Outputs

PSSubnet