Bring your own VHD to Azure (uploading and Downloading VMs to Azure)

Want to move workloads into Azure?

Microsoft Azure has a few options, one of the easiest ways is with Microsoft Azure PowerShell.

$source = “D:\VirtualMachines\MyVm\**OS-DISK**.vhd”
$destination = “https://**mystoragepath**.blob.core.windows.net/vhd/**OS-DISK**.vhd”
 
Add-AzureVhd -LocalFilePath $source -Destination $destination -NumberOfUploaderThreads 5

Once the VHD file has been uploaded, it must be registered as either a OS disk or an additional disk. Use the “-OS” switch to specify whether it is a Linux or Windows OS.

Add-AzureDisk -DiskName ‘**OS-DISK**’ -MediaLocation $destination -Label ‘**OS-DISK**’ -OS Windows *** or Linux

Create a new Cloud/VM and attach the new **OS-DISK**
New-AzureVMConfig -DiskName ‘**OS-DISK**’ -Name ‘**OS-DISK**’ -InstanceSize **small** | Add-AzureDataDisk -Import -DiskName ‘**OS-DISK**’ -LUN 0 | New-AzureVM -ServiceName ‘*CLOUDNAME*’ -Location ‘**West US**’

To download the VHD from Azure the following can be used:

$source = “https://**mystoragepath**.blob.core.windows.net/vhd/**OS-DISK**.vhd”
$destination = “D:\VirtualMachines\MyVm\**OS-DISK**.vhd”

Save-AzureVhd -Source $source -LocalFilePath $destination -NumberOfThreads 5

For Physical or VMWare machines, the Microsoft Virtual Machine Converter 3.0 tool can be used.

http://www.microsoft.com/en-us/download/details.aspx?id=42497

Want to streamline the process ever more for Physical, Hyper-V or VMWare??? Take a look at Azure Site Recovery.

http://azure.microsoft.com/en-us/services/site-recovery/

 

 

Get the latest Azure Windows Image

The following will get you the latest version of the image for the Windows 2012 R2 Server.

<–Start snippet–>

$imageFamily = “Windows Server 2012 R2 Datacenter”

$imagename = Get-AzureVMImage | where {$_.ImageFamily -eq $imageFamily } | sort PublishedDate -Descending | select -expandProperty ImageName -First 1

echo $imagename

<–End Snippet–>

NOTE: Use the $imagename value in your “New-AzureVM” Scripts.

How to create a PaaS website in Azure with PowerShell

Creating a new Website

To create a PaaS website in Azure the following command can be used.

<–Start Snippet –>

$websitelocation = “West US”

$websitename = “MyWebsite”

New-AzureWebsite -Location $websitelocation -Name $websitename

<–End Snippet –>

NOTE:

“test-azurename -Website $websitename”

This command could be run prior to ensure the name is not already in use.

Deployment Slots

To Create a “Deployment Slot” from an existing Website, or to create a new Deployment Slot the following can be used:

<–Start Snippet –>

$websiteslot = “UAT”

New-AzureWebsite -location $websitelocation -name $websitename -slot $websiteslot 

<–End Snippet –>

Swapping Deployment Slots

Switch your SIT – Systems Integration Testing slot with PROD – Production.

<–Start Snippet –>

$prodslot = “PROD”

$sitslot =”SIT”

Switch-AzureWebsiteSlot -Name $websitename -Name -Slot1 $sitslot -Slot2 $prodslot  

<–End Snippet –>

NOTE:

All websites are created in the “AzureWebsites.net” Domain. Each “Slot” are separate Azure sites and will be under the main website slot. As an example a site called SIT would be

SIT.%websitename%.azurewebsites.net

Publishing an Azure Website

If you have a website deployment package you can publish it to azure using the following commands (note you can also publish using FTP,GIT, Visual Studio and other methods):

<–Start Snippet –>

$websitename = “MyWebsite”

$sitslot =”SIT”

$package = “C:\mywebfiles.zip”

Publish-AzureWebsiteProject -Name $websitename -Slot $sitslot  -Package $package

<–End Snippet –>

 

 

How to determine if an Azure web site, cloud, storageaccount or service bus name already exists.

The following can test whether a Microsoft Azure cloud service name, storage service name or service bus namespace name exists or not.

test-Azurename  -Service “CloudServiceName”

test-Azurename  -Storage “StorageAccountName”

test-Azurename  -ServiceBusNamespace “ServiceBusName”

test-Azurename  -Website “WebSiteName”

These parameters will return a “$true” value and can be used to determine how a script will handle a name already in use. This is useful for testing a name prior to creating a cloud service/website/storage account/ service bus automatically.