question

T4K-2862 avatar image
0 Votes"
T4K-2862 asked T4K-2862 commented

Clone an existing VNET to another RG

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?

windows-server-powershellazure-virtual-network
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AlanKinane avatar image
0 Votes"
AlanKinane answered

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://docs.microsoft.com/en-us/powershell/azure/manage-subscriptions-azureps?view=azps-7.5.0#change-the-active-subscription

196953-image.png



image.png (37.5 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AndreasBaumgarten avatar image
0 Votes"
AndreasBaumgarten answered T4K-2862 commented

Hi @T4K-2862 ,

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://docs.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

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Silly question but...

Will initially having a duplicate vnet(all be it with a different name) with the same IP schema not cause an issue/conflict?

0 Votes 0 ·
T4K-2862 avatar image
0 Votes"
T4K-2862 answered T4K-2862 edited

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

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

If it's just the VNET resource with no VMs attached then you can move this resource to another subscription via the portal pretty easily - https://docs.microsoft.com/en-us/azure/azure-resource-manager/management/move-resource-group-and-subscription#use-the-portal

0 Votes 0 ·

yes just the VNETs no VMs or anything else for that matter

but I am looking to clone/copy/duplicate the VNET in a kind of bubble/LAB resource group in a different subscription not moving it from one place to another.

thank you

0 Votes 0 ·
LimitlessTechnology-2700 avatar image
0 Votes"
LimitlessTechnology-2700 answered T4K-2862 commented

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://docs.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--

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello there,

Thank you for your suggestions.

Should I be concerned about peering two VNETs that will have the same IP schema?

0 Votes 0 ·