Sergey Galushko - Fotolia
There are several ways to download virtual disk files associated with Azure VMs in an Azure subscription. You can...
use the Azure portal, Azure PowerShell cmdlets, Azure Storage Explorer and third-party tools that interact with Azure storage accounts. Azure stores VM files on Azure disks. An Azure VM has at least two disks associated with it: a Windows OS disk and a temporary disk. The Windows OS disk is where the Windows OS is installed, whereas the temporary disk is used by Azure for internal and maintenance purposes. You might want to download the Windows OS disk to a local machine for backup and restore purposes. In this article, we'll explain how to download Azure VM disks using PowerShell.
If you want to download Azure VM disks using PowerShell, you'll need to use the Save-AzureRMVHD PowerShell cmdlet. Note that the Azure VM must be stopped before the disk associated with the VM can be downloaded. To begin downloading Azure VM disks using PowerShell, execute the series of PowerShell commands shown below:
- Step 1: Log in to an Azure account by executing the Login-AzureRMAccount cmdlet, which opens a credential popup. Enter the credential to connect to the Azure subscription.
- Step 2: Once connected, execute Get-AzureRMSubscription if you have multiple Azure subscriptions, and list the Azure subscription IDs associated with each Azure subscription.
- Step 3: Select the Azure subscription by executing Select-AzureRMSubscription -SubscriptionID <SubscriptionID here>.
- Step 4: Next, stop the VM by executing Stop-AzureRMVM –ResourceGroupName <Resource Group Name> -Name <Azure Virtual Machine Name>.
- Step 5: Once the Azure VM is stopped, use the PowerShell command below to download each Azure VM disk to a local machine in the C:\Temp\AzureDisks folder:
$DiskPath = "http://storageAccountName.blog.core.Windows.Net/vhdstore/OSImageName.VHD"
Save-AzureRMVHD –ResourceGroupName <Azure Virtual Machine Name> -SourceURI $DiskPath –LocalFilePath "C:\Temp\AzureDisks\VMDisk1.VHD"
Download the complete path for Azure VM disks
As shown above, Save-AzureRMVHD downloads the disk specified in the -SourceURI parameter and stores the downloaded file in the C:\Temp\AzureDisks folder on the local machine. The $DiskPath variable contains the complete path to the disk. You'll need to retrieve the complete path of each disk you want to download before the last PowerShell command can be successful. To retrieve the virtual hard disk path for a VM, go to the Azure portal, navigate to the Azure storage account and then select the VHD to show the complete Uniform Resource Idenitifier. Here is an example of a complete VHD path: http://storageAccountName.blog.core.Windows.Net/vhdstore/OSImageName.VHD. If you want to download another disk for the same VM, all you need do is change the $DiskPath variable and where the disk file should be stored.
Keep your Azure VM IP address
Migrate Azure VMs to Hyper-V
Dig Deeper on Cloud computing architecture
Related Q&A from Nirmal Sharma
Use System Center Virtual Machine Manager and PowerShell to make logical network management easy. Execute a script to display network virtualization ... Continue Reading
Hyper-V replication is easy to use, but there are a number of steps you should take during Hyper-V replication setup to ensure you stay abreast of ... Continue Reading
Manage Hyper-V clusters more easily with PowerShell cmdlets and scripts that automate the retrieval and display of node information, including node ... Continue Reading