Transfer Virtual Machines across various Azure accounts
Moving Virtual Machines (VMs) between different Azure accounts is frequently required by organizations as they grow, reorganize, or oversee multi-tenant environments.
Below are a few typical explanations for why this is done:
- Resource Allocation and Cost Efficiency: Businesses may shift resources to streamline costs as projects progress. Transferring VMs to separate subscriptions or accounts can assist in managing budgets, monitoring usage, and spreading out costs among different departments.
- Security and Compliance: Various departments or projects may possess unique security or compliance needs. Moving virtual machines to other accounts or subscriptions helps in preserving security policies tailored to a particular business unit.
- Testing and Development: Moving VMs between subscriptions or accounts can assist organizations with various environments (like development, staging, and production) in segregating these environments for security and performance purposes.
Initially, you must create a snapshot of the disk you want to use in the other Azure account:
- Navigate to the Disk section and select the particular disk.
2. Generate a snapshot by clicking on the Create snapshot button and filling in all necessary information.
3. You can now view the snapshots that were created in the snapshot window.
You must now set up a Storage Account in the other Azure account in order to utilize the generated snapshot:
- Navigate to the Storage accounts.
2. Click on the Create button.
Steps to Export an Azure Snapshot to a VHD:
- Go to the Storage accounts section located on Account B.
2. Select the Storage account and go to Access Keys on the left side.
Press the Copy button next to the key that will be shown. It could be for either Key 1 or Key 2. Keep this key safe because you will require it in the future.
3. You must now access account A as it contains the snapshot you wish to access from account B.
4. Access the cloud shell by clicking on the button located at the top of the window.
5. Run the command provided to obtain an object for accessing the snapshot.
$sas=Grant-AzSnapshotAccess -ResourceGroupname '<< Resource Group Name >>' -SnapshotName '<< Snapshot Name >>' -DurationInSecond 3600 -Access Read
6. To retrieve a context for the target storage (Account B), run the given command.
$destinationContext= New-AzStorageContext -StorageAccountName '<< Storage Account Name >>' -StorageAccountKey '<< The key you saved from step 2 >>'
7. To create a duplicate of the snapshot in the storage account, run the command provided.
Start-AzStorageBlobCopy -AbsoluteUri $sas.AccessSAS -DestContainer 'snapshots' -DestContext $destinationContext -DestBlob 'Disk.vhd'
Steps to verify Azure Snapshot:
- Go to the Storage accounts section located on Account B.
2. Select the Storage account and go to Containers on the left side. Next, you will observe a snapshots folder with a vhd file inside it.
Generate a new Managed Disk:
- Go to the Marketplace and pick the Managed disk option to generate a new one.
2. Press the create button and provide the disk name, select the source type as ‘storage blob’, and then click on browse for the source blob.
3. Clicking on the browse button will take you to the storage account, where you will need to select a specific vhd file located in the snapshot folder.
4. The final task is to confirm the disk in the Disks section before proceeding to create a virtual machine by clicking on the Create VM button.
If you’d like to update the login credentials for an Azure VM, refer to additional information: https://learn.microsoft.com/en-us/troubleshoot/azure/virtual-machines/windows/reset-rdp
Enjoy :)