Note
Access to this page requires authorization. You can try signing in or .
Access to this page requires authorization. You can try .
Set-AzVirtualNetworkSubnetConfig
- Module:
- Az.Network Module
Updates a subnet configuration for a virtual network.
Syntax
SetByResource (Default)
Set-AzVirtualNetworkSubnetConfig
-Name <String>
-VirtualNetwork <PSVirtualNetwork>
[-AddressPrefix <String[]>]
[-IpamPoolPrefixAllocation <PSIpamPoolPrefixAllocation[]>]
[-NetworkSecurityGroup <PSNetworkSecurityGroup>]
[-RouteTable <PSRouteTable>]
[-InputObject <PSNatGateway>]
[-ServiceEndpoint <String[]>]
[-NetworkIdentifier <PSResourceId>]
[-ServiceEndpointConfig <PSServiceEndpoint[]>]
[-ServiceEndpointPolicy <PSServiceEndpointPolicy[]>]
[-Delegation <PSDelegation[]>]
[-PrivateEndpointNetworkPoliciesFlag <String>]
[-PrivateLinkServiceNetworkPoliciesFlag <String>]
[-IpAllocation <PSIpAllocation[]>]
[-DefaultOutboundAccess <Boolean>]
[-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
SetByResourceId
Set-AzVirtualNetworkSubnetConfig
-Name <String>
-VirtualNetwork <PSVirtualNetwork>
[-AddressPrefix <String[]>]
[-IpamPoolPrefixAllocation <PSIpamPoolPrefixAllocation[]>]
[-NetworkSecurityGroupId <String>]
[-RouteTableId <String>]
[-ResourceId <String>]
[-ServiceEndpoint <String[]>]
[-NetworkIdentifier <PSResourceId>]
[-ServiceEndpointConfig <PSServiceEndpoint[]>]
[-ServiceEndpointPolicy <PSServiceEndpointPolicy[]>]
[-Delegation <PSDelegation[]>]
[-PrivateEndpointNetworkPoliciesFlag <String>]
[-PrivateLinkServiceNetworkPoliciesFlag <String>]
[-IpAllocation <PSIpAllocation[]>]
[-DefaultOutboundAccess <Boolean>]
[-DefaultProfile <IAzureContextContainer>]
[<CommonParameters>]
Description
The Set-AzVirtualNetworkSubnetConfig cmdlet updates a subnet configuration for a virtual network.
Examples
Example 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.
Example 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" -NetworkSecurityGroupId $networkSecurityGroup.Id
$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.
Example 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 eastus2 -AddressPrefix "10.0.0.0/16" -Subnet $frontendSubnet
Set-AzVirtualNetworkSubnetConfig -Name frontendSubnet -VirtualNetwork $virtualNetwork -InputObject $natGateway -AddressPrefix "10.0.0.0/16"
$virtualNetwork | Set-AzVirtualNetwork
Parameters
-AddressPrefix
Specifies a range of IP addresses for a subnet configuration.
Parameter properties
| Type: | String[] |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
-DefaultOutboundAccess
Default outbound connectivity for all VMs in the subnet
Parameter properties
| Type: | |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
-DefaultProfile
The credentials, account, tenant, and subscription used for communication with azure.
Parameter properties
| Type: | IAzureContextContainer |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
| Aliases: | AzContext, AzureRmContext, AzureCredential |
Parameter sets
-Delegation
List of services that have permission to perform operations on this subnet.
Parameter properties
| Type: | |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
-InputObject
Specifies the nat gateway associated with the subnet configuration.
Parameter properties
| Type: | PSNatGateway |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
| Aliases: | NatGateway |
Parameter sets
-IpAllocation
Specifies IpAllocations for a subnet.
Parameter properties
| Type: | |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
-IpamPoolPrefixAllocation
IpamPool to auto allocate from for subnet address prefixes.
Parameter properties
| Type: | |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
-Name
Specifies the name of a subnet configuration that this cmdlet configures.
Parameter properties
| Type: | String |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
-NetworkIdentifier
NetworkIdentifier Value for ServiceEndpoint
Parameter properties
| Type: | PSResourceId |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
-NetworkSecurityGroup
Specifies a NetworkSecurityGroup object.
Parameter properties
| Type: | PSNetworkSecurityGroup |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
-NetworkSecurityGroupId
Specifies the ID of a network security group.
Parameter properties
| Type: | String |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
-PrivateEndpointNetworkPoliciesFlag
Configure to enable or disable applying network policies on private endpoint in the subnet.
Parameter properties
| Type: | String |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
-PrivateLinkServiceNetworkPoliciesFlag
Configure to enable or disable applying network policies on private link service in the subnet.
Parameter properties
| Type: | String |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
-ResourceId
Specifies the Id of NAT Gateway resource associated with the subnet configuration.
Parameter properties
| Type: | String |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
| Aliases: | NatGatewayId |
Parameter sets
-RouteTable
Specifies the route table object that is associated with the network security group.
Parameter properties
| Type: | PSRouteTable |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
-RouteTableId
Specifies the ID of the route table object that is associated with the network security group.
Parameter properties
| Type: | String |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
-ServiceEndpoint
Service Endpoint Value
Parameter properties
| Type: | String[] |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
-ServiceEndpointConfig
Service Endpoint with NetworkIdentifier Value
Parameter properties
| Type: | |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
-ServiceEndpointPolicy
Service Endpoint Policies
Parameter properties
| Type: | |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
-VirtualNetwork
Specifies the VirtualNetwork object that contains the subnet configuration.
Parameter properties
| Type: | PSVirtualNetwork |
| Default value: | None |
| Supports wildcards: | False |
| DontShow: | False |
Parameter sets
CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see about_CommonParameters.
Inputs
PSVirtualNetwork
String
PSNetworkSecurityGroup
PSRouteTable
String
PSServiceEndpointPolicy
PSDelegation
Outputs
PSVirtualNetwork
Related Links
Azure PowerShell
Feedback
Was this page helpful?
