Set-AzVirtualNetworkSubnetConfig

Updates a subnet configuration for a virtual network.

Syntax

Set-AzVirtualNetworkSubnetConfig
   -Name <String>
   -VirtualNetwork <PSVirtualNetwork>
   -AddressPrefix <String[]>
   [-NetworkSecurityGroup <PSNetworkSecurityGroup>]
   [-RouteTable <PSRouteTable>]
   [-InputObject <PSNatGateway>]
   [-ServiceEndpoint <String[]>]
   [-ServiceEndpointPolicy <PSServiceEndpointPolicy[]>]
   [-Delegation <PSDelegation[]>]
   [-PrivateEndpointNetworkPoliciesFlag <String>]
   [-PrivateLinkServiceNetworkPoliciesFlag <String>]
   [-DefaultProfile <IAzureContextContainer>]
   [<CommonParameters>]
Set-AzVirtualNetworkSubnetConfig
   -Name <String>
   -VirtualNetwork <PSVirtualNetwork>
   -AddressPrefix <String[]>
   [-NetworkSecurityGroupId <String>]
   [-RouteTableId <String>]
   [-ResourceId <String>]
   [-ServiceEndpoint <String[]>]
   [-ServiceEndpointPolicy <PSServiceEndpointPolicy[]>]
   [-Delegation <PSDelegation[]>]
   [-PrivateEndpointNetworkPoliciesFlag <String>]
   [-PrivateLinkServiceNetworkPoliciesFlag <String>]
   [-DefaultProfile <IAzureContextContainer>]
   [<CommonParameters>]

Description

The Set-AzVirtualNetworkSubnetConfig cmdlet updates a subnet configuration for a virtual network.

Examples

1: Modify the address prefix of a subnet

New-AzResourceGroup -Name TestResourceGroup -Location centralus

$frontendSubnet = New-AzVirtualNetworkSubnetConfig -Name frontendSubnet -AddressPrefix "10.0.1.0/24"

$virtualNetwork = New-AzVirtualNetwork -Name MyVirtualNetwork -ResourceGroupName TestResourceGroup    
    -Location centralus -AddressPrefix "10.0.0.0/16" -Subnet $frontendSubnet

Set-AzVirtualNetworkSubnetConfig -Name frontendSubnet -VirtualNetwork $virtualNetwork -AddressPrefix "10.0.3.0/23"

$virtualNetwork | Set-AzVirtualNetwork

This example creates a virtual network with one subnet. Then is calls Set-AzVirtualNetworkSubnetConfig to modify the AddressPrefix of the subnet. This only impacts the in-memory representation of the virtual network. Set-AzVirtualNetwork is then called to modify the virtual network in Azure.

2: Add a network security group to a subnet

New-AzResourceGroup -Name TestResourceGroup -Location centralus

$frontendSubnet = New-AzVirtualNetworkSubnetConfig -Name frontendSubnet -AddressPrefix "10.0.1.0/24"

$virtualNetwork = New-AzVirtualNetwork -Name MyVirtualNetwork -ResourceGroupName TestResourceGroup 
    -Location centralus -AddressPrefix "10.0.0.0/16" -Subnet $frontendSubnet

$rdpRule = New-AzNetworkSecurityRuleConfig -Name rdp-rule -Description "Allow RDP" -Access Allow 
    -Protocol Tcp -Direction Inbound -Priority 100 -SourceAddressPrefix Internet -SourcePortRange * -DestinationAddressPrefix * -DestinationPortRange 3389

$networkSecurityGroup = New-AzNetworkSecurityGroup -ResourceGroupName 
    TestResourceGroup -Location centralus -Name "NSG-FrontEnd" -SecurityRules $rdpRule

Set-AzVirtualNetworkSubnetConfig -Name frontendSubnet -VirtualNetwork $virtualNetwork -AddressPrefix 
    "10.0.1.0/24" -NetworkSecurityGroup $networkSecurityGroup

$virtualNetwork | Set-AzVirtualNetwork

This example creates a resource group with one virtual network containing just one subnet. It then creates a network security group with an allow rule for RDP traffic. The Set-AzVirtualNetworkSubnetConfig cmdlet is used to modify the in-memory representation of the frontend subnet so that it points to the newly created network security group. The Set-AzVirtualNetwork cmdlet is then called to write the modified state back to the service.

3: Attach a Nat Gateway to a subnet

$pip = New-AzPublicIpAddress -Name "pip" -ResourceGroupName "natgateway_test" `
   -Location "eastus2" -Sku "Standard" -IdleTimeoutInMinutes 4 -AllocationMethod "static"

$natGateway = New-AzNatGateway -ResourceGroupName "natgateway_test" -Name "nat_gateway" `
   -IdleTimeoutInMinutes 4 -Sku "Standard" -Location "eastus2" -PublicIpAddress $pip

$frontendSubnet = New-AzVirtualNetworkSubnetConfig -Name frontendSubnet -AddressPrefix "10.0.1.0/24" 

$virtualNetwork = New-AzVirtualNetwork -Name MyVirtualNetwork -ResourceGroupName TestResourceGroup 
    -Location centralus -AddressPrefix "10.0.0.0/16" -Subnet $frontendSubnet

Set-AzVirtualNetworkSubnetConfig -Name frontendSubnet -VirtualNetwork $virtualNetwork -InputObject $natGateway 

$virtualNetwork | Set-AzVirtualNetwork

Parameters

-AddressPrefix

Specifies a range of IP addresses for a subnet configuration.

Type:System.String[]
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-DefaultProfile

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

Type:Microsoft.Azure.Commands.Common.Authentication.Abstractions.Core.IAzureContextContainer
Aliases:AzContext, AzureRmContext, AzureCredential
Position:Named
Default value:None
Accept pipeline input:False
Accept wildcard characters:False
-Delegation

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

Type:Microsoft.Azure.Commands.Network.Models.PSDelegation[]
Position:Named
Default value:None
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False
-InputObject

Specifies the nat gateway associated with the subnet configuration.

Type:Microsoft.Azure.Commands.Network.Models.PSNatGateway
Aliases:NatGateway
Position:Named
Default value:None
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False
-Name

Specifies the name of a subnet configuration that this cmdlet configures.

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

Configure to enable or disable applying network policies on private endpoint in the subnet.

Type:String
Position:Named
Default value:None
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False
-PrivateLinkServiceNetworkPoliciesFlag

Configure to enable or disable applying network policies on private link service in the subnet.

Type:String
Position:Named
Default value:None
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False
-ResourceId

Specifies the Id of NAT Gateway resource associated with the subnet configuration.

Type:String
Aliases:NatGatewayId
Position:Named
Default value:None
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False
-RouteTable

Specifies the route table object that is associated with the network security group.

Type:PSRouteTable
Position:Named
Default value:None
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False
-RouteTableId

Specifies the ID of the route table object that is associated with the network security group.

Type:String
Position:Named
Default value:None
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False
-ServiceEndpoint

Service Endpoint Value

Type:System.String[]
Position:Named
Default value:None
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False
-ServiceEndpointPolicy

Service Endpoint Policies

Type:Microsoft.Azure.Commands.Network.Models.PSServiceEndpointPolicy[]
Position:Named
Default value:None
Accept pipeline input:True (ByPropertyName)
Accept wildcard characters:False
-VirtualNetwork

Specifies the VirtualNetwork object that contains the subnet configuration.

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

Inputs

PSVirtualNetwork

String

PSNetworkSecurityGroup

PSRouteTable

System.String[]

Microsoft.Azure.Commands.Network.Models.PSServiceEndpointPolicy[]

Microsoft.Azure.Commands.Network.Models.PSDelegation[]

Outputs

PSVirtualNetwork