Clone an existing VNET to another RG

T4K 1 Reputation point
2022-04-26T22:02:27.92+00:00

Hi,

I have tried to use the script in the following article:

https://techgenix.com/cloning-azure-virtual-network/?unapproved=5120132&moderation-hash=d4e0d04a43a86cdb3ad25fdaeaf4b8cb#comment-5120132

but I get the followoing error message:

VNETClone.ps1: Cannot validate argument on parameter 'SourceVirtualNetworkName'. The "Get-AzVirtualNetwork -Name ($_)" validation script for the argument with value "myvnet" did not return a result of True. Determine why the validation script failed, and then try the command again.

it seems to work for cloning vnets in the same subscription so I am wondering if this is the issue since the VNET I am trying to clone is in a different region/subscription?

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,146 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,377 questions
0 comments No comments
{count} votes

4 answers

Sort by: Most helpful
  1. Alan Kinane 16,786 Reputation points MVP
    2022-04-27T11:12:17.003+00:00

    Without seeing the source code of the script I would think that it is only using the currently selected subscription context. You need to select the active subscription before executing your PowerShell command or else cycle through the subscriptions as part of the script.

    https://learn.microsoft.com/en-us/powershell/azure/manage-subscriptions-azureps?view=azps-7.5.0#change-the-active-subscription

    196953-image.png

    0 comments No comments

  2. Andreas Baumgarten 96,601 Reputation points MVP
    2022-04-27T11:46:55.693+00:00

    Hi @T4K ,

    based on the source coder (https://github.com/andersonpatricio/scripts/blob/master/VNETClone.ps1) the script will clone the vNet in a new resource group in the same subscription.
    It's not possible with this script to clone the vNet to another Azure Subscription.

    What could work (not tested by myself):

    1. Clone the vNet in the same subscription in a new resource group
    2. Use Azure Resource Mover to move the cloned vNet to another Azure Subscription (https://learn.microsoft.com/en-us/azure/resource-mover/select-move-tool)

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten


  3. T4K 1 Reputation point
    2022-04-27T16:07:34.63+00:00

    Thank you both for the feedback.

    I will try the clone in same subscription first then use the Azure resource mover as per instructions and let you know how I get on


  4. Limitless Technology 39,356 Reputation points
    2022-04-28T07:59:32.343+00:00

    Hi T4K-2862,

    It's not possible to clone VNETs across different subscriptions. However, you may be able to create the VNET in the second subscription and then restore a snapshot of your original VNET to the new VNET in the second subscription.

    You can use virtual network peering to connect networks from two different subscriptions. So you can create a networkB in subscription B, then you can use virtual network peering to connect B network to A network.

    Therefore, you could create the VNET in the second subscription and link them.

    Reference:

    https://learn.microsoft.com/en-us/azure/virtual-network/create-peering-different-subscriptions

    I hope this answers your question.

    ----------------------------------------------------------------------------------------------------------------------

    --If the reply is helpful, please Upvote and Accept as answer--