This post assumes you already have Windows Azure PowerShell installed locally with the subscription settings and a storage account setup. If you do not have that already done, then you can view my Getting started with Microsoft Windows Azure PowerShell post for instructions on how to accomplish that.
Load VHD into Azure Storage Account
Here are the contents of my UploadVHDFile.ps1 script, which I used to upload a HyperV VHD into Windows Azure.$moduleLocation = "C:\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell\Azure\Azure.psd1"
$publishSettingsLocation = "<C:\Users\<UserProfile>\Downloads\<SubscriptionName>-credentials.publishsettings>"
$subscriptionName = "<Visual Studio Premium with MSDN>"
$storageAccountName = "<StorageAccountName>"$diskName = "<disk name>"# Source VHD
$vhdsource = '<the complete path of the VHD file example: c:\vhds\myimage.vhd>'# Upload Location
$vhddestination= 'http://' + $storageAccountName + '.blob.core.windows.net/vhds/' + $diskName + '.vhd'
Import-Module $moduleLocation
Import-AzurePublishSettingsFile $publishSettingsLocation
Add-AzureVhd -LocalFilePath $vhdsource -Destination $vhddestination
Add-AzureDisk -OS Windows -MediaLocation $destosvhd -DiskName $diskName
To execute the script file, ...
- I open the Windows Azure PowerShell console as Administrator.
- I change directory, CD, to the folder containing the script. Example CD c:\MyScripts
- I enter in the script filename .\UploadVHDFile.ps1
After serveral minutes / hours, the new DISK will be loaded into your Azure storage account.
Create Virtual Machine from Disk
Here are the contents of my CreateVirtualMachine.ps1 script
file which I used to create a Virtual Machine from the VHD that I loaded into
Windows Azure.
$moduleLocation = "C:\Program Files (x86)\Microsoft SDKs\Windows Azure\PowerShell\Azure\Azure.psd1"
$publishSettingsLocation = "<C:\Users\<UserProfile>\Downloads\<SubscriptionName>-credentials.publishsettings>"
$subscriptionName = "<Visual Studio Premium with MSDN>"
$storageAccountName = "<StorageAccountName>"$diskName = "<disk name>"
$location = 'East US'# Has to be a unique name. Verify with Test-AzureService
$serviceName = "<UNIQUE SERVICE NAME>"
# Server Name
$vmname1 = "<MY VM NAME>"
$migratedVM = New-AzureVMConfig -Name $vmname1 -DiskName $diskName -InstanceSize 'Medium' |
Add-AzureEndpoint -Name 'Remote Desktop' -LocalPort 3389 -Protocol tcp
New-AzureVM -ServiceName $serviceName -Location $location -VMs $migratedVM
To execute the script file, ...
- I open the Windows Azure PowerShell console as Administrator.
- I change directory, CD, to the folder containing the script. Example CD c:\MyScripts
- I enter in the script filename .\CreateVirtualMachine.ps1
After a couple minutes, the new virtual machine will be available for you
to use in Windows Azure.
Benefits and Drawbacks
The huge benefit is that you are able to make a virtual machine
more accessible for your use. You can add more resources be changing the
instance size. You can free up space on your local harddrive. One additional
plus, is that you are able to load images into Windows Azure that are no longer
natively supported through their website, such as Windows Server 2003. The
downside is that you now incur a cost. There is a fee just for storing an image
out in Windows Azure. Plus, you have to pay a cost for the time the Virtual
Machine is allocated. And to be clear, an instance that is Shut Down through
windows is still allocated. You must use the Windows Azure website or PowerShell
console to stopped the instance so that you don't get charged.
No comments:
Post a Comment