How can I assign the Virtual Network durring a deployment via the Azure CLI?

Jason Peterson 96 Reputation points

I am restoring a backup from one resource group to another, both the disks and the VM. I am able to restore everything to the new resource group, however, the new VM is attached to the old resource groups Virtual Network.

I am trying to replicate the functionality of the portal see the attached screen shot.


One can select the Resource Group and Virtual Network to assign to the restored VM. How can I do this via the CLI Interface?

Here is my current command:

az deployment group create --subscription $subscription --resource-group $toResourceGroup --name $vnetName --template-uri "$url?$token" --no-wait --parameters VirtualMachineName=$toVMName

Azure Virtual Network
Azure Virtual Network
An Azure networking service that is used to provision private networks and optionally to connect to on-premises datacenters.
2,199 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jason Peterson 96 Reputation points

    Actually I was able to replicate the portal functions with "--parameters" by following:

    And then adding the "VirtualMachineName", "VirtualNetwork", and "VirtualNetworkResourceGroup" params / overrides.

    az deployment group create \   
    --subscription $subscription \   
    --resource-group $toResourceGroup \   
    --name $restoreName \   
    --template-uri "$url?$token" \   
    --parameters VirtualMachineName=$restoreVMName \   
    --parameters VirtualNetwork=$vnetName \   
    --parameters VirtualNetworkResourceGroup=$toResourceGroup   

    Hope this helps anyone else, thank you!

    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. suvasara-MSFT 10,011 Reputation points

    @Jason Peterson , I have reproduced this in my lab and found that there is no direct CLI command to achieve this. Actually, there two types of restoration,

    1. create new VM and restore from the available RP's. (Possible from portal / indirectly can be achieved using modified Rest API JSON format in CLI )
    2. Replace the existing one. (Azure Doc provided)


    1. Follow this document, take a backup.
    2. create a storage account and restore the disk data to the container.
    3. Now you will be holding three files in your storage account,

    In which, deploy.json file is used to set the dynamic parameter while deploying a template. Change the necessary parameters in that file and redeploy it for the desired configuration.

    az deployment group create \  
      --name ExampleDeployment \  
      --resource-group ExampleGroup \  
      --template-file storage.json \  
      --parameters '@storage.parameters.json'  

    Like in the above provided example. You need to deploy your template with necessary parameters. Also, i am leaving a reference document for you to get more insights about deploying resources with ARM templates and Azure CLI.


    Please do not forget to "Accept the answer" wherever the information provided helps you to help others in the community.

    0 comments No comments