Synopsis
Adds a subnet configuration to a virtual network configuration.
Add-AzVirtualNetworkSubnetConfig -Name <String> -VirtualNetwork <PSVirtualNetwork> [-AddressPrefix <String>] [-NetworkSecurityGroup <NetworkSecurityGroup>] [-ServiceEndpoint <String[]>] [-RoutingTable <RouteTable>] [-Delegation <PSDelegation>] [-PrivateEndpointNetworkPoliciesSetting <String>] [-PrivateLinkServiceNetworkPoliciesSetting <String>] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
Syntax
The following syntax is supported by the cmdlet. For more information, go to about_Syntax.
Add-AzVirtualNetworkSubnetConfig -Name <String> -VirtualNetwork <PSVirtualNetwork> [-AddressPrefix <String>] [-NetworkSecurityGroup <NetworkSecurityGroup>] [-ServiceEndpoint <String[]>] [-RoutingTable <RouteTable>] [-Delegation <PSDelegation>] [-PrivateEndpointNetworkPoliciesSetting <String>] [-PrivateLinkServiceNetworkPoliciesSetting <String>] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
Add-AzVirtualNetworkSubnetConfig -InputObject <PSVirtualNetwork> -Name <String> [-AddressPrefix <String>] [-NetworkSecurityGroup <NetworkSecurityGroup>] [-ServiceEndpoint <String[]>] [-RoutingTable <RouteTable>] [-Delegation <PSDelegation>] [-PrivateEndpointNetworkPoliciesSetting <String>] [-PrivateLinkServiceNetworkPoliciesSetting <String>] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
Description
The Add-AzVirtualNetworkSubnetConfig cmdlet adds a subnet configuration to a virtual network configuration.
This cmdlet is used to create a subnet configuration within an Azure virtual network. You can specify properties such as the subnet name, address prefix, network security group, service endpoints, and route tables. After creating the subnet configuration, you typically use the Set-AzVirtualNetwork cmdlet to apply these changes to the actual virtual network resource in Azure.
Parameters
| Name | Type | Description | Required? |
|---|---|---|---|
| -Name | String |
The name of the subnet. | Yes |
| -VirtualNetwork | PSVirtualNetwork |
The virtual network object to which to add the subnet. This object can be retrieved using the Get-AzVirtualNetwork cmdlet. | Yes |
| -InputObject | PSVirtualNetwork |
The virtual network object to which to add the subnet. This parameter is pipeline-friendly. | Yes |
| -AddressPrefix | String |
The address prefix for the subnet. This is a CIDR notation string (e.g., "10.0.1.0/24"). | No |
| -NetworkSecurityGroup | NetworkSecurityGroup |
The Network Security Group (NSG) object to associate with the subnet. Use Get-AzNetworkSecurityGroup to retrieve an NSG object. | No |
| -ServiceEndpoint | String[] |
An array of strings specifying the service endpoints to enable for the subnet. For example, "Microsoft.Storage", "Microsoft.Sql". | No |
| -RoutingTable | RouteTable |
The route table object to associate with the subnet. Use Get-AzRouteTable to retrieve a route table object. | No |
| -Delegation | PSDelegation |
A delegation object that allows a specific Azure service to manage this subnet. | No |
| -PrivateEndpointNetworkPoliciesSetting | String |
Specifies whether the network policies for Private Endpoint are enabled or disabled for the subnet. Allowed values are "Enabled" or "Disabled". | No |
| -PrivateLinkServiceNetworkPoliciesSetting | String |
Specifies whether the network policies for Private Link Service are enabled or disabled for the subnet. Allowed values are "Enabled" or "Disabled". | No |
| -DefaultProfile | IAzureContextContainer |
The credentials, account, tenant, and subscription used for communication with Azure. | No |
| -WhatIf | SwitchParameter |
Performs the cmdlet's action but does not actually save the changes. For example, the cmdlet will describe what changes it would make to the resource. | No |
| -Confirm | SwitchParameter |
Prompts you for confirmation before running the cmdlet. | No |
Examples
| Description | Code |
|---|---|
|
Example 1: Add a basic subnet configuration to a virtual network
This example retrieves an existing virtual network, adds a new subnet named "MySubnet" with an address prefix, and then updates the virtual network. |
|
|
Example 2: Add a subnet with Network Security Group and Service Endpoints
This example shows how to add a subnet, associate it with a Network Security Group, and enable service endpoints for storage and SQL services. |
|
|
Example 3: Add a subnet with a delegation
This example demonstrates adding a subnet and assigning a delegation for a specific Azure service (e.g., Azure Machine Learning). |
|