Skip to content

Instantly share code, notes, and snippets.

@fabriciosanchez
Created April 10, 2020 17:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fabriciosanchez/14c52aa5f091a02eca3b4f718f1b4fa7 to your computer and use it in GitHub Desktop.
Save fabriciosanchez/14c52aa5f091a02eca3b4f718f1b4fa7 to your computer and use it in GitHub Desktop.
Retrieving existing VNet info and adding two new subnets into it.
# Retriving vnet information
$vnet = Get-AzVirtualNetwork -Name vnet-americasuniversity -ResourceGroupName CoreResources
# Adding appgtw-subnet to the existing VNet
$subnetAGConfig = Add-AzVirtualNetworkSubnetConfig `
-Name appgtw-subnet `
-AddressPrefix 10.1.5.0/28 `
-VirtualNetwork $vnet
# Adding apim-subnet to the existing VNet
$subnetAPIMConfig = Add-AzVirtualNetworkSubnetConfig `
-Name apim-subnet `
-AddressPrefix 10.1.6.0/28 `
-VirtualNetwork $vnet
# Attaching new subnets to the VNet
$vnet | Set-AzVirtualNetwork
# Making sure subnets were successfully added
$vnet.Subnets
# Assign subnet to variables
$appgatewaysubnetdata = $vnet.Subnets[6]
$apimsubnetdata = $vnet.Subnets[5]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment