I recently had a project I was working on in which some inherited Azure VMs were missing the Azure agent and nobody knew the passwords for them. After a quick support call to MS it became apparent I would have to delete the VMs and preserve the disks, download disks, load into hyper-v and manually reset the password. In doing this I learned a few gotchas such as not being able to convert the VHD into a bootable Azure disk unless uploading through the Azure Powershell CLI. Here’s my quick how to upload disks guide.
Installing Azure Powershell
First we will need to install the Azure Powershell Module. This can be accomplished by running Powershell as administrator and entering the following:
When prompted press choose A for yes to all.
Note: If there is any conflict you may need to add the -AllowClobber to the end of the command above.
Login To Azure and Get Publish Settings File
First you will need to log into Azure by entering the following in Powershell
At this point you will be prompted to log into Azure.
The next step will be to get an Azure Publishing Settings file. You can do this by entering the cmdlet below and then importing the file with the following cmdlet:
Import-AzurePublishSettingsFile -PublishSettingsFile “<path to file>”
Select Your Subscription and view Storage Accounts
At this step we will choose which subscription to use (if you have more than one) and list storage accounts so that we know where to upload the disks to.
Warning: If you attempt to upload the VHD through the web GUI instead of using this method it will be created as a block blob not a page blob which prevents you from being able to convert it to a bootable disk for use in the gallery. The only way to do this correctly at the time of this writing is through the Powershell API.
Select-AzureSubscription -SubscriptionId <enter yours here>
Uploading The Azure VHD and Converting It
At this point we are setup for the part we’ve all been waiting for. Make sure your VHD is not thin provisioned and that the VM has the Azure Agent installed and has been sys prepped (if using as a template).
Add-AzureVhd -LocalFilePath “<file path to your VHD>” -Destination “<URL of storage location with your filename after the last />”
This will create an MD5 hash and upload the disk.
To convert the disk we will want to run the following:
Add-AzureDisk -Diskname ‘<name your disk something relevant>’ -MediaLocation ‘<URL where your disk lives in azure storage>’ -Label ‘<label>’ -OS <Choose Windows or Linux>