g.pickardou
g.pickardou

Reputation: 35853

How to update existing AzureRm virtual network using PowerShell?

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:

Question

How can I add new RM Subnet to my existing RM Virtual Network?

Upvotes: 0

Views: 2011

Answers (1)

Rick Rainey
Rick Rainey

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

Related Questions