Set-AzureRmVirtualNetworkSubnetConfig

Configures the goal state for a subnet configuration in a virtual network.

Important

Because Az PowerShell modules now have all the capabilities of AzureRM PowerShell modules and more, we'll retire AzureRM PowerShell modules on 29 February 2024.

To avoid service interruptions, update your scripts that use AzureRM PowerShell modules to use Az PowerShell modules by 29 February 2024. To automatically update your scripts, follow the quickstart guide.

Syntax

Set-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>]
Set-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 Set-AzureRmVirtualNetworkSubnetConfig cmdlet configures the goal state for a subnet configuration in an Azure virtual network.

Examples

1: Modify the address prefix of a subnet

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

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

$virtualNetwork | Set-AzureRmVirtualNetwork

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

2: Add a network security group to a subnet

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

$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

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

$virtualNetwork | Set-AzureRmVirtualNetwork

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-AzureRmVirtualNetworkSubnetConfig 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-AzureRmVirtualNetwork cmdlet is then called to write the modified state back to the service.

Parameters

-AddressPrefix

Specifies a range of IP addresses for a subnet configuration.

Type:List<T>[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.IAzureContextContainer
Aliases: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:List<T>[Microsoft.Azure.Commands.Network.Models.PSDelegation]
Position:Named
Default value:None
Accept pipeline input:True
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
Accept wildcard characters:False
-NetworkSecurityGroupId

Specifies the ID of a network security group.

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

Service Endpoint Value

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

Service Endpoint Policies

Type:List<T>[Microsoft.Azure.Commands.Network.Models.PSServiceEndpointPolicy]
Position:Named
Default value:None
Accept pipeline input:True
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
Accept wildcard characters:False

Inputs

PSVirtualNetwork

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

PSVirtualNetwork