Access your Windows Client from anywhere with Microsoft Azure

When I was in a need to use my Home Computer very badly at some point of time. I was stuck, leaving no clue about wanting that. I’m aware of the Remote Desktop provisioning tools that would give me an access anytime and anywhere. But still I need to have my PC or the Laptop running all the time for accessing the same.

So suddenly something sparked up in my mind about getting an environment done ready to make use of the Windows Client OS anytime, whenever I needed it. So I would tell you one of the great features of Microsoft Azure is VHD mobility. Simply put it means you can upload and download VHDs to and from the cloud.

So let me share you this interesting procedure that I followed to have my Windows Client operating system Virtualized and also making use of it through an RDP with complete access to all my resources like Files, Documents, installed applications like Visual Studio 2013 or the Office Applications. This method is also known as the P2V (Physical to Virtual Conversion)

By this way, you will have your Windows Client Operating system on a most reliable platform utilizing the powerful Microsoft Azure Cloud Environment having Geo-Redundant and other advanced features, that you can enable optionally.

Pre-Requisites for preparing this environment:

1. Windows 8 or 8.1 Operating System Enterprise Edition installed on a Bare Metal Computer (may be a Desktop Tower PC or a Laptop)

2. The Operating system should be installed on a specific 127 GB partition (as it would remain the same virtualized)

3. Sufficient space on the same machine either on the same Hard disk with a different volume or any other attached hard disk for storing the VHD file after conversion.

4. A valid Microsoft Azure subscription (for Server VHDs) and Microsoft Azure MSDN subscription for Windows Client based VHDs to upload.

How to Virtualize?

I would recommend you to use the most lightweight tool named Disk2Vhd, which was developed by Mark Russinovich from Microsoft available at SysInternals Website.

1. Download the Disk2Vhd utility and extract its contents to a local storage and then run the disk2vhd.exe. This will display a window showing up with the options to modify the location, where the VHD needs to be created, etc. And the most interesting factor is, it supports both VHD/VHDX formats for creating the Virtual Hard disk. But due to the Azure guidelines, you would need to use the .VHD extension while converting the same as shown below.

 

2. Now you have three ways to create virtual machines, through the Microsoft Azure Management Portal, Visual Studio and PowerShell.

Let’s start with the Portal approach. You’ll see that the steps to provision a Windows client image do not differ from creating other virtual machines except that you need to be signed in with the Microsoft account that is associated with your active MSDN subscription and use the Azure subscription which you set up using your MSDN Azure benefits. Please find more instructions on how to enable your MSDN Azure benefits here.

Let’s look at how to create a virtual machine from the Azure Portal. The first step is to make sure that you are using an Azure subscription that you set up using your MSDN Azure benefits. Once signed in you can create a new virtual machine by clicking New->Compute->Virtual Machine->From Gallery. This will take you to the Azure Virtual machine gallery. The easiest way to get a list of the MSDN images is to check the little MSDN filtering checkbox as shown below.

Note: The pictures shown below about how to navigate through Menu and features and creating Virtual Machines explained, were intended for the sake of demonstration and not duplicating the content. Also parts of this article with images have been compiled with images referring the Storage Account were sourced from the Azure Knowledge Base Documentation and Virtual Machine creation images are referenced from Boris Scholl on Azure Blog.

Create a Storage account in Azure:

What is a Storage Account?

A Storage account is the highest level of namespace in Microsoft Azure, that is used in storing any kind of data on it like Virtual Machine data and storage services, which is created unique and associated to your Azure Subscription. You need a storage account in Azure to upload a .vhd file to Azure that can be used for creating a virtual machine. You can use the Azure Management Portal to create a storage account. Refer Azure Storage Account to know more about Storage Accounts.

  1. Click Storage Account, and then click Quick Create.

 

Choose whether you will need the Geo-Redundant for High Availability of the Virtual Machine. In general, this feature is used for Windows Servers to have High Availability replicating the Virtual Machines at various Data Centers.

The below picture shows the Storage Tab on the Portal, where you can see your newly created Storage Account being displayed with status as Online.

Then click on the “Containers” tab found on your respective Storage Account on the panel.

Click on “Create a Container” to a virtual container where the VHDs are stored. This is used when selecting the Operating System from the Create Wizard of the Virtual Machine.

Then name your container and choose the access to it. Note: If you choose the option to Public, then you are directly ensuring the access leveraging to the use of public. So its recommended that you limit the access to Private.

Now before we enter the most interesting part of uploading the Virtual Hard disks, we would need to make sure we have Microsoft Azure PowerShell installed, you can refer to How to: Install Microsoft Azure PowerShell.

Lets use the Azure AD way to login to the Power Shell to run the cmdlets.

Type the following command: Add-AzureAccount. A window opens up where you can sign into Azure with your Microsoft account.

Microsoft Azure authenticates and saves the credential information, and then closes the window.

Using the Certificate Method:
  • Open a Microsoft Azure PowerShell window.
  • Type: Get-AzurePublishSettingsFile.
  • A browser window opens and prompts you to download a .publishsettings file. It contains information and a certificate for your Microsoft Azure subscription.
  • Save the .publishsettings file.
  • Type: Import-AzurePublishSettingsFile <PathToFile>Where <PathToFile> is the full path to the .publishsettings file. For more information, see Get Started with Microsoft Azure Cmdlets
Uploading a VHD file to the Azure Storage Account:

After setting up the PowerShell to access the Azure, you would need to run these couple of lines on the Power Shell prompt

Note: The image shown below is an example for the path, where the VHD is located, this will differ with every user’s settings, used from the URL that was shown while creating the Storage Account.

Upload a VHD as a Data Disk (Non OS) (Optional)

As an alternate, if you have the PowerShell already installed and configured and if you are in a need to just upload the VHD as a Data Virtual Hard disk and not a OS VHD, then you can use the below listed cmdlets to add additional VHDs to the Virtual Machine

import-module azure
select-azuresubscription "mysubscriptionname"   $sourceVHD = "MyLocalVhdPathAlongWithVHDextension"
$destinationVHD = "MyStorageAccountContainerLocationAsAUrlWithTheVhdFileExtension"   Add-AzureVhd -LocalFilePath $sourceVHD -Destination $destinationVHD `
             -NumberOfUploaderThreads 5

 

As you can see the code to upload a VHD to your Windows Azure Storage Account is pretty simple.
To make the VHD usable you need to register it with Windows Azure.

Register VHD as a Data Disk

# Register as a plan old data disk 
Add-AzureDisk -DiskName 'mydatadisk' -MediaLocation $destinationVHD `
               -Label 'mydatadisk'

When the code above is run the uploaded VHD will be registered in Windows Azure as a data disk named ‘mydatadisk’. Refresh the portal and you will see it in the Disks list and it will also be available for attaching to a virtual machine.

If you are uploading a VHD with an operating system on it you need to tell that to Windows Azure.

Replace the Long Texts with your respective location values.

How to create images of Virtual Hard Disks (Optional):

You will need to create the image of the Virtual Hard disk, before you could make a use of it. By this process the original VHD is created with a  snapshot and will be stored in your Storage Account, which can be seen listed under the Images tab.

So, Click on Virtual Machines –> Images –> Create an Image

Now, name your image with some desired and User understandable format and fill the spaces with Underscores, if you have any.

Once you create an image, the VHD will be listed under the Virtual Container that you had created. from here you can choose the VHD and click on Open to add that to the Virtual Machine.

Now you will be able to select the respective image, that is listed under the Featured. By this way, you will be able to locate the VHD as an image at any point of time listed under ”My Images”.

Creating the Virtual Machine:

As I have mentioned earlier about the 3 ways to create the Virtual Machine, let me walk you through the first method, which is more convenient for anyone to begin with.

You can either click on the New button found on the Bottom left corner of the portal and Click on Compute—>Virtual Machine—>From gallery which will launch you with this wizard.

So once you choose the Windows 8.1 Operating System, you will shown with the preferences to name the Virtual Machine, which will be your Desktop or the Client Operating System’s Name. (This doesn’t have any association with the System Name of your computer)

Once you have completed assigning the RAM size and the user account that need to be setup to access the Virtual Machine remotely, you would be needed to setup the preferences to choose the Storage Account that you have created having the Virtual Hard disk file (.VHD) available on it and the Availability Set(if needed) and the custom remote desktop ports for secured access of your Virtual machine from anywhere on the globe. Make sure you select the exact Affinity Group as same as the Storage Account, else your Virtual Machine will reside on a different data centre irrespective of the VHDs that reside.

And the Final step would allow you to choose the Security Software that will be installed as a part of the Operating System.

But you would need the VM Agent, which as acts as similar as the Hyper-V integration Services.

You can ignore this our scenario, as In this demonstration I’m using a clean version of Windows 8.1 with Windows Defender as the security software which has Anti-Malware and Anti-Spyware bundled in it and ships FREE as a part of the Operating System.

So, once your Virtual Machine is created, it will take a couple of minutes to initiate and power up.

Now you are done with the setup and you should be able to access your desired Computer, which is now a Virtual Machine, that can be accessed by you anywhere across the globe using the Remote Desktop Connection(as per the login details that can be found by navigating to the Virtual Machine’s settings).

Cmdlets for creating and accessing Virtual Machine resources on Azure through Powershell.

# Sign in azure account
Add-AzureAccount
# Select MSDN subscription if the account has multiple subscriptions
$subscriptionName = "Windows Azure MSDN - Visual Studio Ultimate"
Select-AzureSubscription $subscriptionName
# Find the latest Windows 8 images
$imageFamlyName = "Windows 8.1 Enterprise (x64)"
$win8image = Get-AzureVMImage | ? {$_.ImageFamily -eq $imageFamlyName} | Sort PublishedDate -Descending | Select-Object -First 1
# Create a new storage account
$location = "West US"
$storageAccountName = "MyWindows8Svc"
New-AzureStorageAccount -StorageAccountName $storageAccountName -Location $location -Verbose
Set-AzureSubscription -SubscriptionName $subscriptionName -CurrentStorageAccountName $storageAccountName
# Create a new cloud service
$serviceName = "MyStorageAccount"
New-AzureService -ServiceName $serviceName -Location $location -Verbose
# Create a Windows 8 VM
$vmName = "MyWindows8VM"
$credential = Get-Credential -Message "Enter username and password for the virtual machine administrator"
$username = $credential.UserName
$password = $credential.GetNetworkCredential().Password
New-AzureQuickVM -Windows -ServiceName $serviceName -name $vmName -ImageName $win8image.ImageName -AdminUsername $username -Password $password -WaitForBoot -Verbose

Note: The pictures shown below about how to navigate through Menu and features and creating Virtual Machines explained, were intended for the sake of demonstration and not duplicating the content. Also parts of this article with images have been compiled with images referring the Storage Account were sourced from the Azure Knowledge Base Documentation and Virtual Machine creation images are referenced from Boris Scholl on Azure Blog.

 

Leave a Reply

Your email address will not be published. Required fields are marked *