Reputation: 35853
Context
I have an existing RM virtual network, and now I would like to add a new subnet using PowerShell:
# Create subnet config:
$besub = New-AzureRmVirtualNetworkSubnetConfig -Name $BESubName -AddressPrefix $BESubPrefix
# Get VNet
$vnet = Get-AzureRmVirtualNetwork -Name $VNetName -ResourceGroupName $vmResourceGroup
# Add subnet:
Add-AzureRmVirtualNetworkSubnetConfig -Name $BESubName -AddressPrefix $BESubPrefix -VirtualNetwork $vnet
All commands run successfully however no subnet added to my virtual network.
What I've try so far:
Update-AzureRmVirtualNetwork
, but there is no such a command. Question
How can I add new RM Subnet to my existing RM Virtual Network?
Upvotes: 0
Views: 2011
Reputation: 11246
You are close. You're creating the config but it is not getting applied. This script below will do it for you.
# Get VNet
$vnet = Get-AzureRmVirtualNetwork -Name $VNetName -ResourceGroupName $vmResourceGroup
# Add subnet config to vnet:
Add-AzureRmVirtualNetworkSubnetConfig -Name $BESubName -AddressPrefix $BESubPrefix -VirtualNetwork $vnet
# Apply subnet config to vnet:
Set-AzureRmVirtualNetwork -VirtualNetwork $vnet
Upvotes: 3