none
How to create Subnet using AZ Powershell Module RRS feed

  • Question

  • Hello,

    I am trying to create new subnet inside VNET using below cmd:

    New-AzVirtualNetworkSubnetConfig -Name DEV-VNET-FIN-IND -AddressPrefix 10.2.1.0/16

    Cmd complete successfully, but no subnet is visible.

    Moreover this cmd doesn't take input to link subnet within VNET. How ARM know under which VNET it has to create the subnet?


    Monday, March 11, 2019 1:02 PM

All replies

  • Hi Hasin, 

    You need to use "Add-AzVirtualNetworkSubnetConfig" command. 

    If you are adding a subnet to the existing VNET, you need to get the VNET details in a variable and use it in this command. 

    Here is the reference Document: https://docs.microsoft.com/en-us/powershell/module/azurerm.network/add-azurermvirtualnetworksubnetconfig?view=azurermps-6.13.0

    Regards, 

    Msrini

    Monday, March 11, 2019 1:07 PM
    Moderator
  • Hello,

    I am using Cloud Shell which is upgraded to AZ module from December 2018. I don't see parameter in this cmd to accept VirtualNetwork input. 

    Ref:https://docs.microsoft.com/en-us/powershell/module/az.network/new-azvirtualnetworksubnetconfig?view=azps-1.4.0

    Do you think this is BUG under new module?



    Tuesday, March 12, 2019 7:43 AM
  • Hi Hasin, 

    It does worked for me.

    Module Version is as mentioned below:

    PS Azure:\> module az.network

    ModuleType Version    Name                                ExportedCommands
    ---------- -------    ----                                ----------------
    Script     1.2.1      Az.Network                          {Add-AzApplicationGatewayAuthenticationCertificate, Add-AzApplicationGatewayBackendAddressPool, Add-AzApplicationGatewayBackendHttpSettings, Add-AzApplicationGatewayCustomError...}

    Regards, 

    Msrini


    Tuesday, March 12, 2019 8:25 AM
    Moderator
  • Have you tried creating it once. Does it complete successfully. For me ,it completed, didn't create anything. 

    Also ,do you get any parameter to define VirtualNetwork. 


    Tuesday, March 12, 2019 9:39 AM
  • Hi, 

    If you have an existing VNET, you need to use Add command and then at last you need to do a set-azvnet operation. 

    Here is the sample:

    $virtualNetwork=Get-AzVirtualNetwork -Name MyVirtualNetwork -ResourceGroupName TestResourceGroup
    
    Add-AzVirtualNetworkSubnetConfig -Name backendSubnet -VirtualNetwork $virtualNetwork -AddressPrefix "10.0.2.0/24"
        $virtualNetwork | Set-AzVirtualNetwork

    Regards, 

    Msrini

    Tuesday, March 12, 2019 12:29 PM
    Moderator
  • Hi, 

    Just wanted to check if you have any further question for me. 

    Please 'Mark as answer' if any of the replies helped, so that others in the community who are looking for similar question, can benefit from it.

    Regards, 

    Msrini

    Thursday, March 14, 2019 1:43 PM
    Moderator
  • Hi, 

    Any update on this issue? If the proposed answer helped please remember to mark it as the answer so others who encounter a similar issue can easily find the solution. 

    Regards, 

    Msrini

    Monday, March 18, 2019 9:00 AM
    Moderator