Microsoft Azure

Create an Azure RemoteApp Template from an Azure VM

In this post I will show you how to create an Azure RemoteApp custom template using a virtual machine in the Azure cloud.

Creating a RemoteApp template on-premises and in Azure

In a previous article, I described how to create a custom template using an on-premises Hyper-V virtual machine. That method is pretty slow:

  • You need to create a virtual machine
  • Configure and patch the guest OS
  • Install apps and patch them and the guest OS
  • Sysprep the virtual machine
  • Upload the generalized VHD over limited bandwidth

This is a time consuming and slow method, plus it’s filled with many opportunities to get something wrong, such as accidentally deploying a Generation 2 virtual machine, which cannot be used at this point.

Instead, with this method, you use a virtual machine template in Azure that’s almost ready for RemoteApp. And best of all, the upload is actually an in-Azure data transfer that takes minutes instead of hours.

Sponsored Content

Passwords Haven’t Disappeared Yet

123456. Qwerty. Iloveyou. No, these are not exercises for people who are brand new to typing. Shockingly, they are among the most common passwords that end users choose in 2021. Research has found that the average business user must manually type out, or copy/paste, the credentials to 154 websites per month. We repeatedly got one question that surprised us: “Why would I ever trust a third party with control of my network?

Note: I was working on a method that involved some complicated PowerShell cmdlets to transfer the generalized VHD from a storage blob to RemoteApp. Then I found a new post by Microsoft’s Pierre Roman that offered an alternative way to do the VHD transfer that does not use PowerShell. The guide was missing the final step, which I figured out and shared with Pierre. So thanks to the folks at the Canadian IT Pro Connection website for their help!

Deploy Session Host from Azure Gallery

With this approach, you are going to build the template machine in Azure. Log into the Azure management portal, ensure that you have storage and networking ready for virtual machines, and Click New > Compute > Virtual Machine > From Gallery. Select Windows Server > Windows Server Remote Desktop Session Host as the base template to create your virtual machine.

This template is designed to be used for creating a RemoteApp custom template. EFS is disabled and the necessary roles and features are already installed. Of course, it is a Generation 1 virtual machine with a suitably laid out VHD format virtual hard disk.

Create a new virtual machine from the Azure Gallery (Image Credit: Aidan Finn)
Create a new virtual machine from the Azure Gallery (Image Credit: Aidan Finn)

Go to create a machine. Note that the machine doesn’t need to have a great specification, as a Basic A1 will more than suffice as long as it meets the installation requirements of the software that you are installing. The later step of creating a template will destroy the machine. All we are keeping is the virtual hard disk and that will be deployed by RemoteApp with a larger machine specification.

Install Software

Log into the virtual machine using Connect (Remote Desktop), and install your software. Be sure to patch the machine:

  • Windows Update
  • Any custom patches required for the software

Note: Ignore any pop-up warnings about RDS licensing.

Validate RemoteApp Compatibility

You need to test your new virtual machine for RemoteApp compatibility after you have completed customizing the virtual machine. On the desktop, you will find a shortcut to a script called ValidateRemoteAppImage. Run this script to ensure that what you are producing should still be technically able to run in RemoteApp.

Run ValidateRemoteAppImage to check your new RemoteApp custom template (Image Credit: Aidan Finn)
Run ValidateRemoteAppImage to check your new RemoteApp custom template (Image Credit: Aidan Finn)

Generalize the Image

Do not proceed unless you are ready to create an image. Generalizing a machine will render it inaccessible in Azure. The machine will boot up in the Out of Box Experience (OOBE) and not have Remote Desktop support.

Run the following command to sysprep the virtual machine:

C:\Windows\System32\sysprep\sysprep.exe /generalize /oobe /shutdown

Do not use the /mode:VM parameter.

Sysprep might take quite a while to run in an Azure virtual machine. Wait until the virtual machine is shown with a stopped status in the management portal.

Waiting for the RemoteApp template machine to shut down (Image Credit: Aidan Finn)
Waiting for the RemoteApp template machine to shut down (Image Credit: Aidan Finn)

Capture a Template

The next step will create a template virtual machine. Note that the step will destroy the existing virtual machine and move the virtual hard disk.

Select the virtual machine, and click Capture. Give the image a description and check the box to state that the machine has been generalized using Sysprep. This step takes a couple of minutes.

Capturing an image of the RemoteApp template machine (Image Credit: Aidan Finn)
Capturing an image of the RemoteApp template machine (Image Credit: Aidan Finn)

Import the Template into RemoteApp

A new template will be created and appear in Virtual Machines > Images. We will import this template into RemoteApp so that new app collections can be created from it.

Browse to RemoteApp > Template Images and click Add. Choose the option to Import An Image From Your Virtual Machines Library. Select the newly created virtual machine image, check that you have followed all of the steps and check the box to confirm that everything is correct.

Import the new VM template into RemoteApp (Image Credit: Aidan Finn)
Import the new VM template into RemoteApp (Image Credit: Aidan Finn)

Name the new image, select the Azure region and wait a couple of minutes. The image is imported into RemoteApp pretty quickly. It starts with an Upload Pending status for a minute or so, and then moving from an Import In Progress status to Import Complete.

Don’t rush because the image is not ready yet. Look at the import date. If it’s 00:00 on January 1, 1900 then you need to wait just a little longer. Wait for the image to move to a ready state and for the date to change to the actual upload date. Now you can create a new cloud or hybrid app collection using your custom template.

Note the upload date (Image Credit: Aidan Finn)
Note the upload date (Image Credit: Aidan Finn)

This process is pretty easy and very quick. Furthermore, it might even be completely automatable using Azure Automation.

Related Topics:


Don't have a login but want to join the conversation? Sign up for a Petri Account

Comments (0)

Leave a Reply

Aidan Finn, Microsoft Most Valuable Professional (MVP), has been working in IT since 1996. He has worked as a consultant and administrator for the likes of Innofactor Norway, Amdahl DMR, Fujitsu, Barclays and Hypo Real Estate Bank International where he dealt with large and complex IT infrastructures and MicroWarehouse Ltd. where he worked with Microsoft partners in the small/medium business space.
Don't leave your business open to attack! Come learn how to protect your AD in this FREE masterclass!REGISTER NOW - Thursday, December 2, 2021 @ 1 pm ET

Active Directory (AD) is leveraged by over 90% of enterprises worldwide as the authentication and authorization hub of their IT infrastructure—but its inherent complexity leaves it prone to misconfigurations that can allow attackers to slip into your network and wreak havoc. 

Join this session with Microsoft MVP and MCT Sander Berkouwer, who will explore:

  • Whether you should upgrade your domain controllers to Windows Server
    2019 and beyond
  • Achieving mission impossible: updating DCs within 48 hours
  • How to disable legacy protocols and outdated compatibility options in
    Active Directory

Sponsored by: