Work with Azure Image Builder

My first blog is about using Azure Image Builder (AIB) to create custom images based on Azure marketplace images. By default, all Azure marketplace images are in English US with other region and format settings than we use in Europe. Therefore, it’s necessary to customize the marketplace image.
Changing the language or region is one of the things you can customize with AIB. I choose this example because it’s hard to find info from A to Z about customizing languages on Azure marketplace images with AIB.
In my demo scenario I divided all the steps into separate actions to make it more easy to read, but you can combine it easily in GitHub Actions or Azure DevOps. Also, you can use the variables from Azure DevOps variable groups or retrieve info from Azure key vault to fill the variables.
All scripts can be found on my GitHub and can be used in other environments when changing variables. Always check first before running scripts! |
Scenario:
- You want to use a different language and regional settings for Windows 10 Enterprise or Windows 10 Enterprise multi-session images from the Azure marketplace.
- The image will be created by using Azure Image Builder
- An admin account with global administrator rights and full permissions on the subscription.
- Integrate your Azure tenant with GitHub (Actions) or Azure DevOps (Pipelines) to run the code using yml files.
Prepare for Azure Image Builder (AIB)
We need to have an Azure compute gallery and an image definition. After that we need an identity with a custom role that can be used to create the custom image with Azure Image Builder.
The JSON file used in this script are generic and can be used directly in other environments. If you copy the JSON file to your own location, change the $templateUrl in the script.
The script will do the following actions:
- Get the PowerShell modules and install those (only necessary via yml).
- Create a resource group for storing Azure Virtual Desktop related objects.
- Register Resource Providers for your subscription needed for AIB.
- Check if user identity exists otherwise create it.
- Fill the json template for the custom AIB role with variables.
- Assign the custom AIB role to the user identity created in step 4.
- Create an Azure compute gallery so we can store images build by AIB.
To check if the script ran successful, go to your resource group you mentioned in the script. Open Access Control (IAM) and look for the custom role Azure Image Builder with the managed identity assigned to it.
Download necessary language files
Now we need to gather all the necessary files that we can use as customization input in AIB. Most of the files can be downloaded here: https://docs.microsoft.com/en-us/azure/virtual-desktop/language-packs
The version numbers can be changed overtime so check what version you need.
Language (LangPack) – Windows 10, version 2004 or later Language Pack ISO
LXP (LanguageExperiencePack) – Windows 10, version 2004 or later 02c 2022 LXP ISO
Apps (APP) – Windows 10, version 21H1 or 21H2 Inbox Apps ISO (files in amd64fre folder)
After you downloaded all those files but them together in a folder. APP folder with files like:
Beware contains all apps in the APP folder you want to use with your custom image. You will need the specific language for the app as well. Otherwise, sticky notes will not be “plaknotities” in dutch, and the app will not work properly.
When you have a virtual machine based on the custom image it’s necessary to update the Appx packages per user. You can use this script Schedule-Appx-Update.ps1. |
LangPack folder containing the dutch language pack:
LXP folder with a folder called NL-NL and the files below:
Create custom registry files
Those files are needed for the “Welcome screen and new user accounts settings”. We need to do this step manually so we can export the registry and use it during the AIB process.
Steps you need to do:
- Create a VM based on the marketplace image you want to use in Azure.
- Login with the admin account on the new created VM.
- Install an additional language and select your region.
- Change the regional and Welcome screen and new user accounts settings like you want to use it.
- Export the HKU\.DEFAULT hive, and created a duplicate
- changing the hive to HKU\DEFAULT_USER for the default user account and keeping the original for the Welcome Screen account.
If you want an example, check the reg files here and use change the NLRegion.xml to the region you want to use.
Create package from Language files
Now that we have all the necessary files, create a zip file to bundle all necessary Language files.
Your directory will contain the following files:
Beware that your Language-Files.zip file must be reachable for Azure Image Builder to used it during building process. |
Azure Image Builder
We are ready to start the actual building process with AIB. In this script a lot of other files will be called and used. Those files are all referring to each other in my GitHub location. If you look closely, you see that I also add other customizations besides the language.
The script will do the following actions:
- Generate a version number needed for Azure compute galleries.
- Use the json file to fill it with parameters from variables, Get-AzVMImageSku.ps1 for image Offer and SKU.
- Submit the AIB template to Azure.
- Invoke the build action.
After the process is completed successfully, you will see an image version in your image definitions within Azure compute galleries.
There will also be a resource group called something like IT_\DestinationResourceGroup_\TemplateName_\(GUID) that was used for the AIB process. Within this resource group you will find logging about the AIB process. If the process failed you will not see an image version in Azure compute galleries. In the resource group you can spit the logging from the storage account to retrieve the actual error.
Remove image template
If you want to deploy a new AIB job to build an image the same day, you have to remove the previous one first. You can do this manually by deleting the image file found in the resource group $ResourceGroup you used to build the image. You can also use the script below to remove the remaining files that were left after AIB image creation.
The script will do the following actions:
- It will check for a AIB deployed template in your tenant that has the name W10-MULTI-M365-(Date).
- When a template is found it will check if the state is succeeded (every 5 seconds).
- If the state is succeeded the AIB deployed template will be removed.
AIB AVD Azure Compute Galleries Azure Image Builder Azure Virtual Desktop