Add-AzureRmVirtualNetworkSubnetConfig
Adds a subnet configuration to a virtual network.
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
Add-AzureRmVirtualNetworkSubnetConfig
-Name <String>
-VirtualNetwork <PSVirtualNetwork>
-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>]
Add-AzureRmVirtualNetworkSubnetConfig
-Name <String>
-VirtualNetwork <PSVirtualNetwork>
-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 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.
2: Add a delegation to a subnet being added to an existing virtual network
PS C:\> $vnet = Get-AzureRmVirtualNetwork -Name "myVNet" -ResourceGroupName "myResourceGroup"
PS C:\> $delegation = New-AzureRmDelegation -Name "myDelegation" -ServiceName "Microsoft.Sql/servers"
PS C:\> Add-AzureRmVirtualNetworkSubnetConfig -Name "mySubnet" -VirtualNetwork $vnet -AddressPrefix "10.0.2.0/24" -Delegation $delegation | Set-AzureRmVirtualNetwork
This example first gets an existing vnet. Then, it creates a delegation object in memory. Finally, it creates a new subnet with that delegation that is added to the vnet. The modified configuration is then sent to the server.
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 add.
Type: | String |
Position: | Named |
Default value: | None |
Required: | True |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-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 |
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
Type: | PSRouteTable |
Position: | Named |
Default value: | None |
Required: | False |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-RouteTableId
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 |
-VirtualNetwork
Specifies the VirtualNetwork object in which to add a subnet configuration.
Type: | PSVirtualNetwork |
Position: | Named |
Default value: | None |
Required: | True |
Accept pipeline input: | True |
Accept wildcard characters: | False |
Inputs
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]]